Have you ever been to a site where you notice that media elements such as YouTube videos override other content? This can happen if you have drop down menus, floating bars, 灯箱弹出窗口 etc. In this article, we will show you how to prevent YouTube oEmbed from overriding your WordPress content.
您是否去过一个网站,发现YouTube视频等媒体元素会覆盖其他内容? 如果您有下拉菜单,浮动栏, 灯箱弹出窗口等,则可能发生这种情况。在本文中,我们将向您展示如何防止YouTube oEmbed覆盖您的WordPress内容。
例子:
例子:

When you 嵌入视频 in WordPress, by default it does not have wmode=transparent value. What that means is that video elements have the highest priority and it will override any floating or dynamic element.
当您嵌入视频 WordPress时,默认情况下它没有wmode = transparent值。 这意味着视频元素具有最高优先级,它将覆盖任何浮动或动态元素。
这真的很烦人。那么让我们看看如何在 WordPress 中添加 ?wmode=transparent 到 YouTube 视频,而不使用丑陋的 iFrames 方法。
这真的很烦人。那么我们来看看如何在不使用丑陋的 iFrames 方法的情况下做到这一点?将 wmode=transparent 添加到 WordPress 中的 YouTube 视频。
All you have to do is open your theme’s functions.php file or better yet your 网站的插件文件 and paste the following code:
您所需要做的就是打开主题的functions.php文件或更好的站点插件文件,然后粘贴以下代码:
function add_video_wmode_transparent($html, $url, $attr) {
if ( strpos( $html, "<embed src=" ) !== false )
{ return str_replace('</param><embed', '</param><param name="wmode" value="opaque"></param><embed wmode="opaque" ', $html); }
elseif ( strpos ( $html, 'feature=oembed' ) !== false )
{ return str_replace( 'feature=oembed', 'feature=oembed&wmode=opaque', $html ); }
else
{ return $html; }
}
add_filter( 'embed_oembed_html', 'add_video_wmode_transparent', 10, 3);