Home / functions.php / Add Google doc’s shortcode for psd, ai, svg, and more
  • How to Add Google doc’s shortcode for psd, ai, svg, and more

    new-google-docs-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.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    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");
    
    ( click code to copy )

    wordpress snippet : SHORTCODE

    <>
    [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]
    

    ( WordPress codex functions, hooks, in this snippet. )

    add_shortcode, shortcode_atts, wp,
  • Ben

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