首页 > 解决方案 > Wordpress 自定义模板不支持简码

问题描述

我使用这些说明创建了一个空白模板... https://tips.initpals.com/wordpress-tips/how-to-create-a-blank-page-template-in-wordpress/

<?php /* Template Name: Blank Template */?>
<?php
    if (have_posts()) {
        while (have_posts()): the_post();
        echo strip_tags(get_the_content(), '<p> <a>');
        endwhile;
    }
?>

...但是现在使用该模板的任何页面都不支持短代码。

启用对简码的支持的代码是什么?我不是在寻找该do_shortcode()功能,因为它只运行特定的短代码......我希望在页面中指定短代码而不是模板。

标签: wordpress

解决方案


你在找do_shortcode()吗?

搜索简码内容并通过它们的钩子过滤简码。如果没有定义短代码标签,则将返回内容而不进行任何过滤。当插件被禁用但短代码仍会显示在帖子或内容中时,这可能会导致问题。

来源@https ://developer.wordpress.org/reference/functions/do_shortcode/

<?php if ( have_posts() ):
  while ( have_posts() ): the_post();
    if ( get_the_content() !== '' ):
      echo do_shortcode( get_the_content() );
    endif; 
  endwhile;
endif; ?>

未经测试,但应该可以工作。


推荐阅读