How to edit embed filter for youtube video to allow responsive full width layout

Im trying to edit the suggested embed filter from wordpress.org to make youtube videos always stay 100% width inside its container div, while keeping the appropriate height dimension as needed. Is this possible?

https://codex.wordpress.org/Plugin_API/Filter_Reference/embed_defaults#Examples

add_filter( ’embed_defaults’, ‘modify_embed_defaults’ );
function modify_embed_defaults() {
return array(
‘width’ => 750,
‘height’ => 375
);
}

I initially went ahead and tested out the filter by simply editing the width and height dimensions to fit the wrapper div on my post content, however its virtually impossible to know the necessary height dimension of the video each time since that can vary… in addition, when viewing the post content with embedded videos utilizing this method, the video does not scale appropriately for smaller screens.

Is there a non-plugin solution to this? I was hoping to be able to just add a filter to my child themes functions.php

Thanks,
Shaun

Read more here:: How to edit embed filter for youtube video to allow responsive full width layout

Leave a Reply

Your email address will not be published. Required fields are marked *