Noscope is a bi-weekly journal serving up snacksized portions of pointless stuff since 2001. On a new linode server!
I also do freelance design and usability via dejligt.com

WordPress Trick: Create A Google Viewer PDF Shortcode [Update]

    13:25 on February 25, 2010 ,

Want your PDFs to view through Google Reader? Wrap it in a shortcode like this: Link to a PDF. Drop the following in your functions.php:

function pdflink($attr, $content) {
	return ''.$content.'';
}
add_shortcode('pdf', 'pdflink');

[Update]: Here’s an updated shortcode function which allows you to also embed PDFs using this syntax: Link to a PDF. Note how it’s just a tad shorter, and you don’t have to remember the “href” parameter, though you can still use it.

function pdflink($attr, $content) {
	if ($attr['href']) {
		return ''.$content.'';
	} else {
		$src = str_replace("=", "", $attr[0]);
		return ''.$content.'';
	}
}
add_shortcode('pdf', 'pdflink');

Also, here’s an example PDF link using the above code: Link to a PDF.

Comment

  1. wordpress_tw tweeted this.

Leave a Reply

Have something to say? Jump right in!

(required)
(required)