Created
January 13, 2017 16:29
-
-
Save mrwweb/4e396b3211729a54b8d0c96254aa64f3 to your computer and use it in GitHub Desktop.
Quick little WordPress plugin to embed PDFs with Google's PDF viewer. See: https://community.nten.org/communities/community-home/digestviewer/viewthread?MessageKey=98bbef1e-d60f-453b-a039-562cfbe52b26&CommunityKey=76218446-efc9-4c49-9462-59b5d88daecb&tab=digestviewer&UserKey=3f274014-ea5f-4f43-a232-e59886306781&sKey=9dd0bd09908d46de93f9#bm0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Google PDF Viewer Shortcode | |
Description: Display a PDF in the browser with Google's PDF viewer. Usage: [pdf]http://example.org/some-public-document.pdf[/pdf]. Can specify optional width and height attribrutes like this [pdf width="100" height="100"]http://example.org/a-very-tiny-document.pdf[/pdf] | |
Version: 1.0 | |
Author: Mark Root-Wiley | |
Author URI: https://mrwweb.com | |
*/ | |
/* a shortcode for embedding PDFs via Google Docs viewer */ | |
function nten_pdf_shortcode( $atts, $content = '' ) { | |
if( '' === $content || '.pdf' !== substr( $content, -4 ) ) { | |
return; | |
} | |
$atts = shortcode_atts( array( | |
'width' => '600', | |
'height' => '775' | |
), $atts, 'pdf' ); | |
return '<iframe src="https://docs.google.com/viewer?url=' . esc_url( $content ) . '&embedded=true" style="width:' . intval( $atts['width'] ) . 'px; height:' . intval( $atts['height'] ) . 'px;" frameborder="0" class="us-embedded-pdf"></iframe>'; | |
} | |
add_shortcode( 'pdf', 'nten_pdf_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment