Did you know, we can create PDF viewer shorcode in WordPress with easy steps? All need to do only using Google Docs viewer tools and integrated it into our WordPress site. The first thing we should do, is written shortcode function in our functions.php theme files.
Simple Method PDF Shortcode functions
function pdflink($attr, $content) {
if ($attr['href']) {
return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>';
} else {
$src = str_replace("=", "", $attr[0]);
return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $src . '">'.$content.'</a>';
}
}
add_shortcode('pdf', 'pdflink');
And done, how to use PDF Shortcode? it’s simple just write down this tiny code on your content
[pdf href="http://yoursite.com/linktoyour/file.pdf"View PDF[/pdf]
Thanks for NoScope for this great tips and we hope you can do it on your own WordPress site



Hello
Do you happen to know if you can remove the print and download links from the viewer?
Thanks
Hey thanks, great tips! Never thought about using Google Docs as a direct document viewer. Guess it makes sense. I’ll be sure to use it in a future project!
Pingback: wp-popular.com » Blog Archive » How To Create a PDF viewer shortcode in WordPress # WordPress Tricks & Tips
great tips, thanks for sharing
is this violate google TOS ?
The only problem with this is, if the person viewing your website is not signed in to google – they will not see your pdf docs.
Does anybody know a workaround for this problem?
I will re write this trick with another way, I hope will fix this problem..
yes this is awesome and i will be incorporating this in my education blog. Although Nathan is right, it would be ideal for all to see. awesome, im still going to do it as my students have gmail, and most of their work is on a private level.
Thanks,
Anays