Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#30660 closed defect (bug) (invalid)

Embed handler filter callback not firing (e.g. wp_embed_handler_youtube)

Reported by: eterps Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: Embeds Keywords: close
Focuses: ui, administration Cc:


I'm trying to create a filter for the new auto-embed feature in Wordpress 4.0 and edit the default output for the embed tag with a filter function.

I have a snippet set up like this in my theme's function.php:

add_filter( 'wp_embed_handler_youtube', 'bigger_youtube_embeds', 10, 4);
function bigger_youtube_embeds($embed, $attr, $url, $rawattr) {
    // alter the $embed string...
    return $embed;

I tried this after viewing the following documentation: https://developer.wordpress.org/reference/hooks/wp_embed_handler_youtube/

My filter function never runs, though, and I'm not even sure when it is supposed to run. I've tried setting Xdebug breakpoints inside the filter function, and using var_dump, and returning a gibberish string ('hello world') from the callback, but nothing ever happens.

Steps to reproduce:

  1. add a filter or action (I've tried both) for wp_embed_handler_youtube and define a callback.
  2. Create a new post and paste in a YouTube URL.
  3. The auto-embed code will run and create an embedded video.
  4. Save the post
  5. View the post

At no point in this process did my filter callback ever get called.

My Env:

  • Ubuntu 12.04
  • PHP 5.4.34
  • Wordpress 4.0.1
  • Client: Mac OS X + Chrome 39 / Firefox 34

Change History (4)

#1 @johnbillion
7 years ago

  • Keywords reporter-feedback close added
  • Version changed from 4.0.1 to 4.0

The description for the wp_embed_handler_youtube filter is misleading. This only filters the embed code for YouTube URLs which start with youtube.com/embed rather then the normal video URLs which start with youtube.com/watch.

Most likely the filter you're looking for is oembed_result which filters the markup for the embed after it's returned from the provider.

Also note that the auto-embed functionality isn't new in WordPress, it's been there years. The new functionality in 4.0 adds additional support for youtube.com/embed URLs (#24660).

#2 @eterps
7 years ago

  • Keywords reporter-feedback removed
  • Resolution set to invalid
  • Status changed from new to closed

Ahh, sorry. I'm fairly new to wordpress and didn't realize this functionality had been around so long. Yes, the oembed_result filter works as expected. Thanks :)

#3 @SergeyBiryukov
7 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.