admin管理员组文章数量:1130349
Building a theme with Boostrap 4 and WordPress 5.0.1. Under Bootstrap's documentation for embed video the following format is required for responsive videos:
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="" allowfullscreen></iframe>
</div>
Searching under the tag oembed and reading the following Q&As:
- How to wrap oEmbed-embedded video in DIV tags inside the_content?
- Responsive iframe using Bootstrap
Using wp-test with my function of:
function oembed_mod($cache,$url,$attr,$post_ID) {
if (stripos($cache,'youtube') !== 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')) {
$classes[] = 'vimeo-video';
}
if (false !== strpos($url,'youtube')) {
$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);
I can modify Youtube and Vimeo videos and I get:
<div class="youtube-video embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" width="500" height="281" src="" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</div>
but on my Twitter post testing I get:
<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="">October 16, 2012</a></p>
</blockquote>
<p><script async src=".js" charset="utf-8"></script>
</div>
Is the Twitter feed apart of the oembed? Is there a preferred approach to video only manipulation so that I can ignore Twitter feeds or do I need to write a conditional on the variable $cache if twitter-tweet exists?
Edit:
I can get my function to work with:
if (stripos($cache,'twitter') !== false) :
return $cache;
endif;
but I think my end goal is to know if there is a better/elegant way to go about this. Current setup seems to be somewhat a hack and as already mentioned this doesn't address all youtube URLs unless I code a foreach look for the needle.
Building a theme with Boostrap 4 and WordPress 5.0.1. Under Bootstrap's documentation for embed video the following format is required for responsive videos:
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="https://www.youtube/embed/zpOULjyy-n8?rel=0" allowfullscreen></iframe>
</div>
Searching under the tag oembed and reading the following Q&As:
- How to wrap oEmbed-embedded video in DIV tags inside the_content?
- Responsive iframe using Bootstrap
Using wp-test with my function of:
function oembed_mod($cache,$url,$attr,$post_ID) {
if (stripos($cache,'youtube') !== 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')) {
$classes[] = 'vimeo-video';
}
if (false !== strpos($url,'youtube')) {
$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);
I can modify Youtube and Vimeo videos and I get:
<div class="youtube-video embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" width="500" height="281" src="https://www.youtube/embed/nwe-H6l4beM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</div>
but on my Twitter post testing I get:
<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/carlsmith/status/258214236126322689?ref_src=twsrc%5Etfw">October 16, 2012</a></p>
</blockquote>
<p><script async src="https://platform.twitter/widgets.js" charset="utf-8"></script>
</div>
Is the Twitter feed apart of the oembed? Is there a preferred approach to video only manipulation so that I can ignore Twitter feeds or do I need to write a conditional on the variable $cache if twitter-tweet exists?
Edit:
I can get my function to work with:
if (stripos($cache,'twitter') !== false) :
return $cache;
endif;
but I think my end goal is to know if there is a better/elegant way to go about this. Current setup seems to be somewhat a hack and as already mentioned this doesn't address all youtube URLs unless I code a foreach look for the needle.
Share Improve this question edited Dec 20, 2018 at 2:55 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Dec 19, 2018 at 17:18 user9447user9447 1,7927 gold badges30 silver badges55 bronze badges1 Answer
Reset to default 0You should be doing some sort of check at the beginning of your function to ensure you're in an oembed that you actually want to mod. something like
if (strpos($url, youtube) === false && strpos($url, vimeo) === false) {
return $cache;
}
Although you might want to elaborate on that to catch shortened urls like youtu.be as well.
Building a theme with Boostrap 4 and WordPress 5.0.1. Under Bootstrap's documentation for embed video the following format is required for responsive videos:
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="" allowfullscreen></iframe>
</div>
Searching under the tag oembed and reading the following Q&As:
- How to wrap oEmbed-embedded video in DIV tags inside the_content?
- Responsive iframe using Bootstrap
Using wp-test with my function of:
function oembed_mod($cache,$url,$attr,$post_ID) {
if (stripos($cache,'youtube') !== 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')) {
$classes[] = 'vimeo-video';
}
if (false !== strpos($url,'youtube')) {
$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);
I can modify Youtube and Vimeo videos and I get:
<div class="youtube-video embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" width="500" height="281" src="" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</div>
but on my Twitter post testing I get:
<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="">October 16, 2012</a></p>
</blockquote>
<p><script async src=".js" charset="utf-8"></script>
</div>
Is the Twitter feed apart of the oembed? Is there a preferred approach to video only manipulation so that I can ignore Twitter feeds or do I need to write a conditional on the variable $cache if twitter-tweet exists?
Edit:
I can get my function to work with:
if (stripos($cache,'twitter') !== false) :
return $cache;
endif;
but I think my end goal is to know if there is a better/elegant way to go about this. Current setup seems to be somewhat a hack and as already mentioned this doesn't address all youtube URLs unless I code a foreach look for the needle.
Building a theme with Boostrap 4 and WordPress 5.0.1. Under Bootstrap's documentation for embed video the following format is required for responsive videos:
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="https://www.youtube/embed/zpOULjyy-n8?rel=0" allowfullscreen></iframe>
</div>
Searching under the tag oembed and reading the following Q&As:
- How to wrap oEmbed-embedded video in DIV tags inside the_content?
- Responsive iframe using Bootstrap
Using wp-test with my function of:
function oembed_mod($cache,$url,$attr,$post_ID) {
if (stripos($cache,'youtube') !== 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')) {
$classes[] = 'vimeo-video';
}
if (false !== strpos($url,'youtube')) {
$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);
I can modify Youtube and Vimeo videos and I get:
<div class="youtube-video embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" width="500" height="281" src="https://www.youtube/embed/nwe-H6l4beM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</div>
but on my Twitter post testing I get:
<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/carlsmith/status/258214236126322689?ref_src=twsrc%5Etfw">October 16, 2012</a></p>
</blockquote>
<p><script async src="https://platform.twitter/widgets.js" charset="utf-8"></script>
</div>
Is the Twitter feed apart of the oembed? Is there a preferred approach to video only manipulation so that I can ignore Twitter feeds or do I need to write a conditional on the variable $cache if twitter-tweet exists?
Edit:
I can get my function to work with:
if (stripos($cache,'twitter') !== false) :
return $cache;
endif;
but I think my end goal is to know if there is a better/elegant way to go about this. Current setup seems to be somewhat a hack and as already mentioned this doesn't address all youtube URLs unless I code a foreach look for the needle.
Share Improve this question edited Dec 20, 2018 at 2:55 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Dec 19, 2018 at 17:18 user9447user9447 1,7927 gold badges30 silver badges55 bronze badges1 Answer
Reset to default 0You should be doing some sort of check at the beginning of your function to ensure you're in an oembed that you actually want to mod. something like
if (strpos($url, youtube) === false && strpos($url, vimeo) === false) {
return $cache;
}
Although you might want to elaborate on that to catch shortened urls like youtu.be as well.
本文标签: feedWhy is my oembed function modifying Twitter embed
版权声明:本文标题:feed - Why is my oembed function modifying Twitter embed? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749083043a2313346.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论