简体   繁体   中英

Removing iframe tags in Wordpress

I am working on a wordpress theme and WP now uses oEmbed to automatically turn known links into widgets. The problem here is that the widgets are not responsive (they do not keep the same aspect ratio and adjust to the screen size).

The site is http://testsite1.seyoum.net/ Note that the theme I am using is a child theme of twentyfifteen. You can download the theme files here: https://onedrive.live.com/redir?resid=B9CDD4D34FF06A75!97938&authkey=!AEj9VpYkCRL0SEE&ithint=file%2crar

I have done some research and found this video: https://youtu.be/Dm0YnuQeROI In the video he removes the with and height properties of the iframe. The problem for me is that these tags are added automatically by oEmbedd so I need some kind of filter that removes/ignores the height and width tags in the iframe.

I am trying to alter an iframe. More spesifically I want to remove the height and width tags of the iframe by using (what I believe to be) filters.

Example: I want to change this

<iframe width="660" height="400" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?visual=true&amp;color=000000&amp;download=false&amp;show_user=false&amp;sharing=false&amp;show_comments=false&amp;show_playcount=false&amp;hide_related=true&amp;url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F192992432&amp;show_artwork=false&amp;&amp;"></iframe>

To this: (The width="660" height="400" is gone)

<iframe scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?visual=true&amp;color=000000&amp;download=false&amp;show_user=false&amp;sharing=false&amp;show_comments=false&amp;show_playcount=false&amp;hide_related=true&amp;url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F192992432&amp;show_artwork=false&amp;&amp;"></iframe>

I am not familiar with php and it is hard to find articles I can understand so please help me out if you can.

Try to use

function mycustom_embed_defaults($embed_size){ 
    // Applies for all embedded media 
    /*$embed_size['width'] = 827;*/ // Adjust the width of the player 
    // $embed_size['height'] = 120; // Adjust the height of the player 
    unset($embed_size['width']); 
    unset($embed_size['height']); 
    return $embed_size; // Return new size 
}

or

function mycustom_embed_defaults($embed_size){ 
    // Applies for all embedded media 
    $embed_size['width'] = "auto"; // Adjust the width of the player 
    $embed_size['height'] = "auto"; // Adjust the height of the player 
    return $embed_size; // Return new size 
}

or

function mycustom_embed_defaults($embed_size){ 
    // Applies for all embedded media 
    $embed_size['width'] = "100%"; // Adjust the width of the player 
    $embed_size['height'] = "100%"; // Adjust the height of the player 
    return $embed_size; // Return new size 
}

The problem is that your plugin seems to need the width property... All you have to do is to know what you want it to be... It doesn't have to be a pixel value...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM