当我尝试使用以下方式之一嵌入YouTube视频时:
[embed]
短代码[embed]
短代码)我在编辑的视野中看到了这段视频:
但是在前端视图中,使用以下代码:
$content_desktop = do_shortcode(get_the_content());
我看到了
[embed]
短代码或使用WYSIWYG编辑器时:字面上没有我检查过的东西:
是否有什么众所周知的原因导致了这一切?
发布于 2018-01-28 12:18:03
我刚刚查看了WP_Embed类的源代码,看起来它们实际上并不是在注册一个短代码,而是链接到the_content
过滤器。
将代码更改为
$content_desktop = apply_filters("the_content", get_the_content());
或者手动触发他们的过滤器,比如
$content_desktop = WP_Embed::run_shortcode(get_the_content());
或者,如果你想要一个对象:
$myembeds = new WP_Embed;
$content_desktop = $myembeds->run_shortcode(get_the_content());
https://wordpress.stackexchange.com/questions/292413
复制相似问题