WordPress tip: Create a PDF viewer shortcode

WordPress tip: Create a PDF viewer shortcode

The first step is to paste the following code into your functions.php file:

function pdflink($attr, $content) {
	return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>';
}
add_shortcode('pdf', 'pdflink');

Once you saved the file, you’ll be able to use the shortcode on your posts and page. Here is the syntax:

[pdf href="http://yoursite.com/linktoyour/file.pdf"]View PDF[/pdf]

Thanks to Noscope for this great shortcode!

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

WordPress tip: Create a PDF viewer shortcode

Leave a Reply

Your email address will not be published. Required fields are marked *