Last active
April 4, 2016 23:16
-
-
Save huypn/8cd5f4fc0560e3251a2ce53e80386fe7 to your computer and use it in GitHub Desktop.
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 | |
wp_embed_register_handler( 'jsfiddle', '#https?://jsfiddle.net/.*#i', 'huypham_embed_handler_jsfiddle' ); | |
function huypham_embed_handler_jsfiddle( $url ){ | |
global $content_width; | |
$url = $url[0]; | |
$height = '300'; | |
$width = $content_width?$content_width:'100%'; | |
$query = parse_url($url,PHP_URL_QUERY); | |
$url = trailingslashit(preg_replace('#\?.+#i', '', $url)); | |
parse_str($query,$query); | |
if (isset($query['height'])) { | |
$height = $query['height']; | |
} | |
if (isset($query['width'])) { | |
$width = $query['width']; | |
} | |
if( !preg_match( '#/embedded/#i', $url ) ) | |
$url .= 'embedded/'; | |
return '<iframe width="'.$width.'" height="'.$height.'" src="'.$url.'" allowfullscreen="allowfullscreen" frameborder="0"></iframe>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment