Become Wordpress Professional - Your Ultimate Wordpress Guide

Thursday, 2 May 2013

How to Create a PDF File Viewer in Wordpress

How to create a PDF viewer in WordPress
If your blog is based on WordPress and you would like to display a PDF file on your blog post, then you can easily integrate it by the trick given below. It is a snippet of code to place in your theme's functions.php file and then you can simply use a short-code to display a PDF file viewer on your particular blog post or a page.

Displaying PDF Viewer using Shortcode 

Your PDF file is going to be viewed by Google Docs, integrated into your blog post or page. To create a PDF viewer in your WordPress site follow the steps described below:

1. Login into your WordPress admin Dashboard area.

2. Then Go to Appearance >> Editor

3. Now locate the file name functions.php

4. Scroll down to the end, then simply copy the code below and paste it at the bottom

function pdflink($attr, $content) {
return '<a class="pdf" href="' . $attr['href'] . '">'.$content.'</a>'; 
add_shortcode('pdf', 'pdflink');

5. Save the functions.php file.

The above code basically tells wordpress to add a shortcode [pdf] that will help us easily integrate a PDF file inside a post or a page.

Now, to display a PDF that is view-able using Google Docs, you first have to upload the PDF file by using your Media panel in WordPress. Upload your PDF file and then copy the URL of the file destination.

Use this snippet of shortcode in your post to display PDF viewer.

[pdf href=""]View PDF[/pdf]

Change the destination file location in the above code and you are done. Now you will be able to see the PDF file integrated into your wordpress site.


Post a Comment

Please Avoid Spamming. Comments will be moderated before they are published.