- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
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.
@maddtechwf there’s no such filter hook named embed_oembed_html
.
Read more about, the_content filter hook and this stackflow answer
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.
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.
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 '<div class="embed-responsive embed-responsive-16by9">' . $cache . '</div>';
}