Enable google docs shortcode for .pdf documents

Adding this snippet to the functions.php of your wordpress theme will setup [pdf] shortcode to link PDF documents to Google docs online viewer.

 

 

function pdflink($attr, $content) {
if ($attr['href']) {
return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>';
} else {
$src = str_replace("=", "", $attr[0]);
return '<a class="pdf" href="http://docs.google.com/viewer?url=' . $src . '">'.$content.'</a>';
}
}
add_shortcode('pdf', 'pdflink');

[pdf href="http://wpsnipp.com/uploads/file.pdf"]My PDF file[/pdf]

Be Sociable, Share!

Leave a comment