How to Create a PDF Viewer Shortcode For Your WordPress Blog!

PDFIf you are sharing and using the PDF file on your WordPress blog then you might want to consider creating a shortcode to allow your readers to quickly open them through Google Docs.

 

To create a PDF viewer shortcode on WordPress, you have to follow 2 steps:

 

  • The first step is to paste the following code into your functions.php file:
function pdflink($attr, $content) {
	return '<a href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>';
}
add_shortcode('pdf', 'pdflink');
  • Once you saved the file, this code will allow you to use a shortcode to share your PDF files. Whenever you want to link to a PDF file, you should use the following code in your post:
[pdf href="http://yoursite.com/linktoyour/file.pdf"]View PDF[/pdf]

Thanks to Noscope for this great shortcode!