Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wycks
Created March 23, 2012 23:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wycks/2176359 to your computer and use it in GitHub Desktop.
Save wycks/2176359 to your computer and use it in GitHub Desktop.
PDF Cross Browser Embed Plugin Wordpress
<?php
/*
Plugin Name: PDF Cross Browser Embed
Plugin URI: http://#
Description: Embeds PDf into a post/page using default media uploader using a cross browser freindly iframe
Version: 1.0
Author: Wycks
License: GPL2
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
add_filter('media_send_to_editor', 'my_filter_pdf', 20, 3);
function my_filter_pdf($html, $id) {
$attachment = get_post($id); //fetching attachment by $id passed through
$mime_type = $attachment->post_mime_type; //getting the mime-type
if ($mime_type == 'application/pdf') { //checking mime-type
$src = wp_get_attachment_url( $id );
$html = '<iframe width="500" height="500" src="'.$src.'"></iframe>';
return $html; // return new $html
}
return $html;
}
?>
@jkudish
Copy link

jkudish commented Jun 1, 2012

your function closes too early...

    }
    return $html; // return new $html

should read:

    return $html; // return new $html
 }

@wycks
Copy link
Author

wycks commented Jun 1, 2012

Thanks, had not noticed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment