使用Boostrap 4和WordPress 5.0.1构建主题。在Bootstrap的文档中embed video 响应视频需要以下格式:
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="https://www.youtube.com/embed/zpOULjyy-n8?rel=0" allowfullscreen></iframe>
</div>
在标记下搜索
oembed 并阅读以下问题;作为:
使用
wp-test 我的职能是:
function oembed_mod($cache,$url,$attr,$post_ID) {
if (stripos($cache,\'youtube.com\') !== FALSE && stripos($cache,\'iframe\') !== FALSE) {
$cache = str_replace(\'<iframe\',\'<iframe class="embed-responsive-item" \', $cache);
}
$classes = [];
// Add these classes to all embeds.
$classes_all = array(
\'embed-responsive\',
\'embed-responsive-16by9\',
);
// Check for different providers and add appropriate classes.
if (false !== strpos($url,\'vimeo.com\')) {
$classes[] = \'vimeo-video\';
}
if (false !== strpos($url,\'youtube.com\')) {
$classes[] = \'youtube-video\';
}
$classes = array_merge($classes,$classes_all);
return \'<div class="\' . esc_attr(implode($classes,\' \')) . \'">\' . $cache . \'</div>\';
}
add_filter(\'embed_oembed_html\',\'oembed_mod\',99,4);
我可以修改Youtube和Vimeo视频,我得到:
<div class="youtube-video embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" width="500" height="281" src="https://www.youtube.com/embed/nwe-H6l4beM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</div>
但在我的推特帖子测试中,我发现:
<div class="embed-responsive embed-responsive-16by9">
<blockquote class="twitter-tweet" data-width="500" data-dnt="true">
<p lang="en" dir="ltr">Doing what you “know” locks you in a prison of the past. Uncertainty is the path to an innovative future.</p>
<p>— Carl Smith (@carlsmith) <a href="https://twitter.com/carlsmith/status/258214236126322689?ref_src=twsrc%5Etfw">October 16, 2012</a></p>
</blockquote>
<p><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
推特提要是oembed的一部分吗?是否有一种只处理视频的首选方法,这样我就可以忽略推特提要,还是需要在变量上写一个条件
$cache
如果
twitter-tweet
是否存在?
编辑:
我可以使用我的函数:
if (stripos($cache,\'twitter.com\') !== false) :
return $cache;
endif;
但我想我的最终目标是知道是否有更好/优雅的方法来实现这一点。当前的设置似乎有点像黑客,如前所述,除非我为每一个指针的外观编写代码,否则这并不能解决所有youtube URL。