Home Forums Front-end Issues How to embed pdf on page


How to embed pdf on page

  • Hi, I uploading pdf as file, into custom post type. And I use this code in order to display it on page:

    <?php $pdf = get_field( ‘pdf’ ); ?>
    <?php if ( $pdf ) { ?>
    “><?php echo $pdf[‘filename’]; ?>
    <?php } ?>

    And result is pdf file displayed as an attachment to post. Is there way to embed it into page?

    I use pdf-embedder plugin on default posts, and it embed pdf, but not on custom one.

    Any help appreciated

  • Most of your code was removed, you need to use code tags.

    However, using the plugin you mention you need to call the shortcode for it to work. I’m using the same plugin on a site, the code looks like this

    echo do_shortcode('[pdf-embedder url="'.get_field('drawing').'"]');

    my field is set to return the URL of the pdf file.

  • Thanks, it better now, but I got a weird error:

    Missing PDF “”

    Here’s code again

    <?php $pdf = get_field( 'pdf' ); ?>
    <?php if ( $pdf ) { ?>
    <?php echo do_shortcode('[pdf-embedder url="'.get_field('pdf').'"]'); ?>
    <?php } ?>
  • You need to change the file field to return the url or you need to extract the url from the array that is being returned by ACF. This is explained in the file field documentation

  • Worked, like a charm. Thanks a bunch, YOU’ve made my day.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.