WordPress YouTube native responsive

The native YouTube url when you embed into wordpress content is not responsive so we need to add a code to this iframe or embed

so we need to add to functions.php this code

what this code do is to search for the embed code of youtube and add to it

in order to change it with css

add_filter('embed_oembed_html', 'wrap_embed_with_div', 10, 3);

function wrap_embed_with_div($html, $url, $attr) {
        return "<div class=\"responsive-container\">".$html."</div>";

and this css code to your css file or theme settings css

.responsive-container {
        position: relative;
        padding-bottom: 50.25%;
        padding-top: 30px;
        height: 0;
        overflow: hidden;
        margin-bottom: 1em;
.responsive-container iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;

hope i helped someone in this world 🙂