当我在wordpress中使用tinymce插件添加youtube视频时,它在可视化编辑器部分中运行良好。
但在我的自定义模板中,它只是显示
[embed]https://youtube.com/my-video-link[/embed]
对不起,也许有一个明显的答案,但我是全新的wordpress和谷歌只是给了我相反的我想要的答案有关如何从博客文章内容中逃脱html ..
我不知道我错过了什么,但谢谢你事先提前
修改
我没有使用the_content()
函数来回显我的post_content但是我尝试了它的工作方式,所以这个函数必须使用一个函数来转换我在youtube iframe中的embed标签。
因为我需要从某个类别获得最后一篇文章我存储了
变量get_posts(['category_name' => 'My Category Name', 'showpost' => 1])
然后我$mySpecificCategory[0]->post_content
。事实上,我不知道这是不是好方法。
解
好的,我在wordpress support找到了解决方案。这是:
<?php echo apply_filters( 'the_content', $mySpecificCategory[0]->post_content) ?>
答案 0 :(得分:0)
使用do_shortcode()
函数将嵌入代码转换为youtube iframe:
echo do_shortcode( $content );
查看http://codex.wordpress.org/Function_Reference/do_shortcode了解详情
答案 1 :(得分:0)
短代码替换为短代码处理程序输出的内容。
实施例
add_filter( 'the_content', 'do_shortcode', 11 ); // From shortcodes.php
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode( '[gallery]' );
// In case there is opening and closing shortcode.
echo do_shortcode( '[iscorrect]' . $text_to_be_wrapped_in_shortcode . '[/iscorrect]' );
// Use shortcodes in text widgets.
add_filter( 'widget_text', 'do_shortcode' );
// Use shortcodes in form like Landing Page Template.
echo do_shortcode( '[contact-form-7 id="91" title="quote"]' );
// Store the short code in a variable.
$var = do_shortcode( '[gallery]' );
echo $var;
答案 2 :(得分:0)
<强>解强>
好的,我在wordpress support找到了解决方案。这是:
<?php echo apply_filters( 'the_content', $mySpecificCategory[0]->post_content) ?>