I tried the example in this link https://codex.wordpress.org/Function_Reference/wp_embed_register_handler but it didn’t work. This is my whole code:
add_action('init', function() {
wp_embed_register_handler( 'forbes', '#http://(?:www|video)\.forbes\.com/(?:video/embed/embed\.html|embedvideo/)\?show=([\d]+)&format=frame&height=([\d]+)&width=([\d]+)&video=(.+?)($|&)#i', 'wp_embed_handler_forbes' );
});
function wp_embed_handler_forbes( $matches, $attr, $url, $rawattr ) {
$embed = sprintf(
'<iframe src="http://www.forbes.com/video/embed/embed.html?show=%1$s&format=frame&height=%2$s&width=%3$s&video=%4$s&mode=render" width="%3$spx" height="%2$spx" frameborder="0" scrolling="no" marginwidth="0" marginheight="0"></iframe>',
esc_attr($matches[1]),
esc_attr($matches[2]),
esc_attr($matches[3]),
esc_attr($matches[4])
);
return apply_filters( 'embed_forbes', $embed, $matches, $attr, $url, $rawattr );
}
Any ideas why this is not working?
2 Answers
I modified the example you posted from the Codex:
/**
* Embed support for Forbes videos
*
* Usage Example:
*
* http://www.forbes.com/video/5049647995001/
*/
add_action( 'init', function()
{
wp_embed_register_handler(
'forbes',
'#http://www\.forbes\.com/video/([\d]+)/?#i',
'wp_embed_handler_forbes'
);
} );
function wp_embed_handler_forbes( $matches, $attr, $url, $rawattr )
{
$embed = sprintf(
'<iframe class="forbes-video" src="https://players.brightcove.net/2097119709001/598f142b-5fda-4057-8ece-b03c43222b3f_default/index.html?videoId=%1$s" width="600" height="400" frameborder="0" scrolling="no"></iframe>',
esc_attr( $matches[1] )
);
return apply_filters( 'embed_forbes', $embed, $matches, $attr, $url, $rawattr );
}
Currently the iframe
has a fixed height and width.
You can hopefully adjust it to your needs, e.g. using the theme’s $content_width
or pass on the height/width information directly from the pasted video url.
Update: I added a warning to the Codex page, until a better example is posted.