PDF Viewer Shortcode: How To Create One For Your WordPress Blog

Steven10 responsesWordPress
Advertise Here

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:

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:

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

Learn how I made $36,482 online in the past 12 months.

Simply input your best email below to get started.

Advertise Here


  1. 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!

    1. Anon

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

    2. 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!

    3. Michelle

      *I wouldn’t completely rule out emails.

  2. Shad

    Very helpful, thanks!

  3. Jony

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

    1. 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

    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..

    1. 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

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

Learn how I made $36,482 online in the past 12 months.

Simply input your best email below to get started.

No thanks, I have enough money