Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Issue with WordPress embed_oembed_html

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #209311
    TWG
    Participant

    I’m trying to wrap all YouTube videos with a Bootstrap embed-responsive class but for some reason it is not firing.

    add_filter('embed_oembed_html', 'custom_youtube_settings', 99, 4);
    function custom_youtube_settings($cache, $url, $attr, $post_id)
    {
        return '<div class="embed-responsive embed-responsive-16by9">' . $html . '</div>';
    }
    

    I only have a few other items above this in my functions.php.

    #209325
    Alen
    Participant

    @maddtechwf there’s no such filter hook named embed_oembed_html.

    Read more about, the_content filter hook and this stackflow answer

    #209327
    TWG
    Participant

    Hi @Alen – There actually is a hook by that name. I also had Jetpack Embed enabled and that was causing the code to not work. Everything is good to go now.

    #209366
    Alen
    Participant

    You’re right, it’s listed here https://developer.wordpress.org/reference/hooks/embed_oembed_html/ can you post your solution or whatever you did for future reference.

    #236892
    vandigroup
    Participant

    The only issue with the original code here is that you need to return $cache rather than $html. The correct code would be:

    add_filter('embed_oembed_html', 'custom_youtube_settings', 99, 4);
    function custom_youtube_settings($cache, $url, $attr, $post_id) {
    return '&lt;div class="embed-responsive embed-responsive-16by9"&gt;' . $cache . '&lt;/div&gt;';
    }

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Other’ is closed to new topics and replies.