X

Add Google doc’s shortcode for psd, ai, svg, and more

On Friday I posted a great snippet by Joen Asmussen the Google PDF shortcode. I wanted to post an updated version primarily because the Google online viewer supports many more file types not just PDF. The supported types are .DOC, .DOCX, .XLS, .XLSX, .PPT, .PPTX, .PDF, .PAGES, .AI, .PSD, .TIFF, .DXF, .SVG, .EPS, .PS, .TTF, .XPS I added a class attribute to the shortcode that you could use to display an icon for the file type link or style the links with the default icon class.

View sample PSD with Google viewer.


function wps_viewer($atts, $content = null) {
	extract(shortcode_atts(array(
		"href" => 'http://',
		"class" => ''
	), $atts));
	return '<a href="http://docs.google.com/viewer?url='.$href.'" class="'.$class.' icon">'.$content.'</a>';
}
add_shortcode("doc", "wps_viewer");
[doc class="psd" href="http://www.wpsnipp.com/file.psd"]my PSD file name[/doc]
[doc class="ai" href="http://www.wpsnipp.com/file.ai"]my AI file name[/doc]
[doc class="svg" href="http://www.wpsnipp.com/file.svg"]my SVG file name[/doc]

Comments  Leave a Reply

  1. I asked on stack and they said this was impossible, you’ve proved them wrong my friend!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!