large shade tree

Navigation

Information

Recent Posts

Shade Tree Sites |Building Better Websites

WordPress Shortcode: Embed a PDF in an iframe

WordPress Shortcode: Embed a PDF in an iframe

Shortcode to display a PDF file on your WordPress website:

The PDF is loaded through Google docs and then displayed in an iframe, on your site.
First paste the code below into your functions.php file:

function cwc_viewpdf($attr, $url) {
    return '<iframe src="http://docs.google.com/viewer?url=' . $url . '&embedded=true" style="width:' .$attr['width']. '; height:' .$attr['height']. ';" frameborder="0">Your browser should support iFrame to view this PDF document</iframe>';
}
add_shortcode('embedpdf', 'cwc_viewpdf');

Then, use the following to display a PDF.   You can define width and height to fit your website.

[embedpdf width="600px" height="500px"]http://yourwebsite.com/wp-content/yourpdf.pdf[/embedpdf]

Source: CatsWhoCode.com