【问题标题】:Removing iframe tags in Wordpress删除 Wordpress 中的 iframe 标签
【发布时间】:2015-11-04 07:38:12
【问题描述】:

我正在开发一个 wordpress 主题,WP 现在使用 oEmbed 自动将已知链接转换为小部件。这里的问题是小部件没有响应(它们不保持相同的纵横比并调整到屏幕尺寸)。

网站是http://testsite1.seyoum.net/ 请注意,我使用的主题是 25 的子主题。您可以在此处下载主题文件: https://onedrive.live.com/redir?resid=B9CDD4D34FF06A75!97938&authkey=!AEj9VpYkCRL0SEE&ithint=file%2crar

我做了一些研究,发现了这个视频:https://youtu.be/Dm0YnuQeROI 在视频中,他删除了 iframe 的 with 和 height 属性。我的问题是这些标签是由 oEmbedd 自动添加的,所以我需要某种过滤器来删除/忽略 iframe 中的高度和宽度标签。

我正在尝试更改 iframe。更特别的是,我想通过使用(我认为是)过滤器来删除 iframe 的高度和宽度标签。

示例: 我想改变这个

<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>

对此: (width="660" height="400" 没了)

<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>

我不熟悉php,很难找到我能理解的文章,所以如果可以的话,请帮助我。

【问题讨论】:

  • with 应该定义或使用 auto

标签: php html wordpress


【解决方案1】:

尝试使用

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 
}

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 
}

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 
}

问题是您的插件似乎需要 width 属性...您所要做的就是知道您想要它是什么...它不一定是像素值...

【讨论】:

  • 最后一个建议$embed_size['width'] = "100%"; 产生&lt;iframe width="100" height=" 但问题是我实际上需要删除高度和宽度属性,而不是更改它们。另外我不使用插件。嵌入是 Wordpress 的默认 oEmbed
  • 对不起,我完全迷路了。我可能缺乏PHP的基本知识。我很想重新编写问题并询问 “如何从 iframe 中删除高度和宽度属性,而不实际从 iframe 本身删除这些值” 也许从头开始会更好。
  • 我认为最好开始一个新问题并尝试从头开始。我确实在每个 php 文件中查找了“embed_defaults”,但我找不到它。这意味着我一定从一开始就搞砸了。我想我需要一些帮助才能正确设置 php,对不起。感谢您的帮助。
  • 如果你找不到它,那是因为它从未被调用过,事实上,你是否自己制作了这个函数(使用复制粘贴作为常见问题解答)?你可能错过了一部分
  • 我可能确实错过了那部分,是的。那我怎么称呼它?我的 php 技能太糟糕了。
猜你喜欢
  • 2011-11-09
  • 1970-01-01
  • 2017-10-30
  • 2013-07-16
  • 2018-01-18
  • 1970-01-01
  • 2016-01-26
  • 2023-01-04
  • 1970-01-01
相关资源
最近更新 更多