Create WordPress Shortcode To View PDFs


If your website has some PDF documents which you would like to display to your visitors then it will be usful to the user if they can open it using Google Docs.

In the article I will explain how you can make you WordPress have a shortcode for PDFs to display using Google Docs.

Why Use Google Docs

Google Docs is a free application from Google which makes it easy to view, edit and share documents through your Google account. Therefore if a user can open up PDFs in Google Docs it will make it very easy for them to save the document and share it with other people on their Google Document lists.

Code To Create Shortcode To Open Google Docs

function google_pdflink($attr, $content) {
	return '<a href="' . $attr['href'] . '">'.$content.'</a>';
add_shortcode('google_pdf', 'google_pdflink');
Back to top

Learn how to code with Treehouse

  • Learn projects with access to 1000+ videos
  • Practice live with our Code Challenge Engine
  • Get help in our members-only forums

Start with a 7 day free trial