javascript - 添加包含任何 iframe、wordpress 的 div

标签 javascript wordpress iframe

我正在使用此功能使 Youtube 视频具有响应性。这会在 Youtube 嵌入代码周围添加一个 div。

add_filter( 'embed_oembed_html', 'custom_oembed_filter', 10, 4 ) ;

function custom_oembed_filter($html, $url, $attr, $post_ID) {
    $return = '<div class="video-container">'.$html.'</div>';
    return $return;
}

它很好用,但我只是从别人的教程中复制过来的,所以我不明白它到底在做什么。我想修改它,以便它也添加围绕 libsyn iframe 的相同 div。

这就是 Youtube iframe 代码的样子,上面的函数添加了一个包络 div。

<iframe src="//www.youtube.com/embed/MKif3vEhgdg" frameborder="0" allowfullscreen="allowfullscreen" style="width: 690px; height: 388.125px;"></iframe>

这是Libsyn iframe,当前函数没有添加div。

<iframe style="border: none;" src="//html5-player.libsyn.com/embed/episode/id/4016467/height/360/width/640/theme/standard/direction/no/autoplay/no/autonext/no/thumbnail/yes/preload/no/no_addthis/no/" width="640" height="360" scrolling="no" allowfullscreen="allowfullscreen"></iframe>

如何修改函数以将相同的 div 添加到两个 iframe?

最佳答案

由于 libsyn 可能不是默认的 oembed 提供程序,您可以尝试使用以下代码在您的 functions.php 文件中注册它:

function custom_oembed_provider() {
    wp_oembed_add_provider( '//html5-player.libsyn.com/*', '', false );
}
add_action( 'init', 'custom_oembed_provider' );

或者您可以使用 jQuery:

jQuery(document).ready(function() {
    jQuery('iframe[src*="html5-player.libsyn.com"]').wrap('<div class="video-container" />');
});

否则,只需使用纯 HTML:

<div class="video-container"><iframe style="border: none;" src="//html5-player.libsyn.com/embed/episode/id/4016467/height/360/width/640/theme/standard/direction/no/autoplay/no/autonext/no/thumbnail/yes/preload/no/no_addthis/no/" width="640" height="360" scrolling="no" allowfullscreen="allowfullscreen"></iframe></div>

关于javascript - 添加包含任何 iframe、wordpress 的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34276318/

相关文章:

MySQL根据wp_meta值更新wp_posts?

javascript - 使用 JavaScript 或 jQuery 跟踪实际 HTML 元素的 View (与仅页面加载相比)

javascript - 为什么 IE 以外的浏览器中 DOM Document 对象中缺少 XML 属性

javascript - Moment.js 和具有数据属性时区的 Moment Timezone

php - 动态生成 W​​ordPress 短代码

javascript - 如何使用 Javascript 根据按钮状态更改 iframe 源

firefox - 如何在 Chrome 和 Firefox 中使用 YouTube iFrame API?

javascript - 将 NSDictionary 从 Javascript 传递到 JavascriptCore 中的 Objective-c

javascript - 是否可以在 cli 报告中仅显示 Mocha 测试套件的摘要?

javascript - 获取iframe中的元素