Create a PDF viewer shortcode

by Blog Tips on July 5, 2010

If you’re using PDF files on your WordPress blog, it could be very cool to give your users the chance to open them using Google Docs. The following recipe will show you how you can do that.

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, you’ll be able to use the shortcode on your posts and page. Here is the syntax:

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

Did you enjoy this article? Give us some link love, and don't forget to bookmark this page on Delicious.

Notes : Join us and read the Guidelines to submit your guest posts.
Subscribe free updates via: RSS Feed | Email | Twitter

Related Articles

Leave a Comment

Previous post:

Next post: