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>',

return apply_filters( 'embed_forbes', $embed, $matches, $attr, $url, $rawattr );

Any ideas why this is not working?

  • What url are you testing? – birgire Sep 6 '16 at 9:02
  • this one http://www.forbes.com/video/5049647995001/ – kmligue Sep 6 '16 at 9:41
  • that's far away from the accepted url structure in the handler, I guess the Forbes embed service has changed since this example was added. – birgire Sep 6 '16 at 10:10

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()

} );

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.

  • Thanks! Code works on post editor. I can see embed in blog post. Currently im using buddypress on my site. When posting the link in activity page it didn't work. According to buddypress(codex.buddypress.org/getting-started/embeds) they are using the native wp embeds functionality. Could this be a buddypress issue? – kmligue Sep 7 '16 at 1:57
  • Glad to hear it worked. It's been a while since I last used BuddyPress, but if it's working in the post content editor but not in activity pages then it sounds like an issue for BuddyPress. @KelvinMartinLigue – birgire Sep 7 '16 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.