Get my FREE ebook:
"SEO FOR BLOGS: The Ultimate Guide"
Limited Time Offer!

How To Create A PDF Viewer Shortcode For Your WordPress Blog

If you are regularly sharing PDF files with your blog readers, you might want to consider creating a shortcode to allow your readers to quickly open them through Google Docs.

The first thing to do is to paste the following piece of code in the functions.php file of your WordPress theme:

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

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:

1
[pdf href="http://anywebsite.com/linkto/file.pdf"]View PDF[/pdf]
Commenting Contest
If you enjoyed this article, Get email updates
(It's Free)
Sté Kerwer
Post written by: Sté Kerwer
Bonjour from France. My name is Stéphane Kerwer and Dukeo.com is my blog. I do most of the heavy lifting in here but from time to time, you may see some guest posts. If you wish to receive updates about Dukeo, subscribe to RSS Feed, follow Dukeo on twitter or become a fan on Facebook.
10 Comments
  1. Liz
    Liz

    I have never thought about sharing pdf files through links on my blog… I usually just email them through email campaigns, but this would have a lot more reach probably!

    • Anon
      Anon

      Nobody uses email anymore, this would be way more effective.

      • Michelle
        Michelle

        I think there’s a middle-ground here, people. I would completely rule out emails as an effective tool, and I would definitely get your blog up to speed with file sharing. The thing is, you want to reach as many people as possible, so you want to make sure you are able to do that through every medium available. So do both!

        • Michelle
          Michelle

          *I wouldn’t completely rule out emails.

  2. Shad
    Shad

    Very helpful, thanks!

  3. Jony
    Jony

    What kind of PDF files do you share? Like some examples.

    • Michelle
      Michelle

      You can share anything, spreadsheets, photos, essays, you name it. The possibilities are endless, and it’s a lot more effective than email blasts or redirecting them to a hub of some kind.

  4. Shad
    Shad

    I have no idea how to write codes like this, so I’m always either scrambling to find someone who does know, or I just stay out of touch with technology. How hard is it to learn code? I don’t have a ton of time but it does seem like I need to catch up..

    • Anon
      Anon

      Just take a class at your local community college. An intro class would teach you basics, and from there you could find out if you wanted to continue learning, if you take to it well, so to speak. It’s not very hard.

  5. Dana
    Dana

    That is really good advice, my son just did that and he learned a lot in a specific subject for very little money!

arrow