Posted By

gd6d on 06/11/10


Tagged

wordpress pdf shortcode


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

themolitor
tspitzr
alexeihidalgo
srdjan


Wordpress shortcode : Simple embedding PDF


 / Published in: PHP
 

URL: http://www.wprecipes.com/wordpress-tip-create-a-pdf-viewer-shortcode

  1. /*
  2.  * Code modified by: Street.Walker [at] masedi [dot] net
  3.  * Simple embedding PDF, Presentation file to blog post with Google view.
  4.  * ex: http://docs.google.com/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true
  5.  * or: http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true
  6.  * embed it with HTML iFrame: <iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
  7.  * Source from: http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html
  8.  * implementation for WordPress: use shortcodes
  9.  * usage: [embedpdf width="600px" height="500px"]http://infolab.stanford.edu/pub/papers/google.pdf[/embedpdf]
  10.  * adopted from: http://www.wprecipes.com/wordpress-tip-create-a-pdf-viewer-shortcode
  11.  *
  12.  * Copy the code and paste it to your functions.php file under your active theme
  13.  */
  14.  
  15. function viewpdf($attr, $url) {
  16. return '<iframe src="http://docs.google.com/viewer?url=' . $url . '&embedded=true" style="width:' .$attr['width']. '; height:' .$attr['height']. ';" frameborder="0">Your browser should support iFrame to view this PDF document</iframe>';
  17. }
  18. add_shortcode('embedpdf', 'viewpdf');

Report this snippet  

You need to login to post a comment.