Skip to content

Instantly share code, notes, and snippets.

@dobsondev
Created March 25, 2014 17:48
Show Gist options
  • Save dobsondev/9767276 to your computer and use it in GitHub Desktop.
Save dobsondev/9767276 to your computer and use it in GitHub Desktop.
Shortcode for Embedding PDF's - Used in DobsonDev Shortcodes Plugin for WordPress
<?php
/* Adds a shortcode for displaying PDF's Inline */
function dobson_embed_PDF($atts) {
extract(shortcode_atts(array(
'source' => "Invalid Source",
'width' => "100%",
'height' => "600",
), $atts));
$source_headers = @get_headers($source);
if (strpos($source_headers[0], '404 Not Found')) {
return '<p> Invalid PDF source. Please check your PDF source. </p>';
} else {
return '<object width="' . $width . '" height="' . $height . '" type="application/pdf" data="'
. $source . '"></object>';
}
}
add_shortcode('embedPDF', 'dobson_embed_pdf');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment