WordPress不会解释博客文章中的html标签


Wordpress doesn't interpret html tag in blogpost

当我在wordpress中使用tinymce插件添加youtube视频时,它在可视化编辑器部分效果很好。

但是在我的自定义模板中,它只显示

[embed]https://youtube.com/my-video-link[/embed]

抱歉,也许有一个明显的答案,但我对wordpress完全陌生,谷歌只是给了我相反的答案,我想要如何从博客文章内容中转义html。

我不知道我错过了什么,但提前谢谢你

编辑

我不使用the_content()函数来回显我的post_content但我尝试并且它有效,因此该函数必须使用函数来转换我在 youtube iframe 中的嵌入标签。因为我需要从某些类别中获取最后一篇文章,所以我存储 get_posts(['category_name' => 'My Category Name', 'showpost' => 1])变量中,那么我$mySpecificCategory[0]->post_content.事实上,我不知道这是否是好方法。

溶液

好的,所以我在wordpress支持中找到了解决方案。这是:

<?php echo apply_filters( 'the_content',  $mySpecificCategory[0]->post_content) ?>

使用do_shortcode()函数将嵌入标签转换为 youtube iframe:

echo do_shortcode( $content );

查看 http://codex.wordpress.org/Function_Reference/do_shortcode 了解更多详情

解决方案

好的,所以我在wordpress支持中找到了解决方案。这是:

<?php echo apply_filters( 'the_content',  $mySpecificCategory[0]->post_content) ?>

短代码替换为短代码处理程序的输出的内容。

例子

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;