Skip to content

Instantly share code, notes, and snippets.

@huypn
Last active April 4, 2016 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huypn/8cd5f4fc0560e3251a2ce53e80386fe7 to your computer and use it in GitHub Desktop.
Save huypn/8cd5f4fc0560e3251a2ce53e80386fe7 to your computer and use it in GitHub Desktop.
<?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