Skip to content

Instantly share code, notes, and snippets.

@Otto42
Created June 24, 2013 19:54
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 Otto42/5853020 to your computer and use it in GitHub Desktop.
Save Otto42/5853020 to your computer and use it in GitHub Desktop.
mlb.tv embed code for a WordPress plugin
<?php
function mlbtv_embed_register_handler() {
wp_embed_register_handler( 'mlbtv', '|https?://wapc.mlb.com/play/\?content_id=([0-9]*)?#?|i', 'mlbtv_embed_handler' );
}
add_action( 'init', 'mlbtv_embed_register_handler' );
function mlbtv_embed_handler( $matches, $attr, $url, $rawattr ) {
if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
$width = (int) $rawattr['width'];
$height = (int) $rawattr['height'];
} else {
list( $width, $height ) = wp_expand_dimensions( 400, 224, $attr['width'], $attr['height'] );
}
return "<iframe src='http://wapc.mlb.com/shared/video/embed/embed.html?content_id={$matches[1]}&width={$width}&height={$height}&property=mlb' width='{$width}' height='{$height}' frameborder='0'>Your browser does not support iframes.</iframe>";
}
@rerraw
Copy link

rerraw commented Nov 17, 2015

thank you very useful
but if you can explain for me how i can add support embed handler for facebook videos and posts?

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