Home / functions.php / Enable google docs shortcode for .pdf documents
  • How to Enable google docs shortcode for .pdf documents

    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.

    ( click code to copy )

    wordpress snippet : PHP

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

    wordpress snippet : SHORTCODE

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

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

    add_shortcode, wp,