ban*_*ing 3 php embed youtube wordpress video
WordPress会自动将页面/帖子内容中的YouTube网址转换为嵌入式iframe视频.
它尊重startYouTube网址中的参数(如果存在),但它不尊重end参数(如果存在).
因此,我需要找到处理这种自动YouTube嵌入功能的WordPress代码,以便我可以希望在我自己的过滤器中使用(使用此解决方案)将end满足要求.
我已经通过了搜查class-wp-embed.php,class-oembed.php并media.php在文件的/wp-includes/目录,并在后者,认为我找到了我所需要的代码...
apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr )
...但是这个过滤器似乎没有被调用.
谁能指出我正确的方向?
小智 6
我有同样的问题,但没有找到答案.所以这是工作解决方案:
add_filter('embed_oembed_html', 'my_theme_embed_handler_oembed_youtube', 10, 4);
function my_theme_embed_handler_oembed_youtube($html, $url, $attr, $post_ID) {
if (strpos($url, 'youtube.com')!==false) {
/* YOU CAN CHANGE RESULT HTML CODE HERE */
$html = '<div class="youtube-wrap">'.$html.'</div>';
}
return $html;
}
Run Code Online (Sandbox Code Playgroud)