Create a gist now

Instantly share code, notes, and snippets.

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
jkudish commented Jun 1, 2012

your function closes too early...

    }
    return $html; // return new $html

should read:

    return $html; // return new $html
 }
@wycks
Owner
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