wordpress - 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()
功能,因为它只运行特定的短代码......我希望在页面中指定短代码而不是模板。
解决方案
你在找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; ?>
未经测试,但应该可以工作。
推荐阅读
- javascript - 如何在使用 fetch 定位 JSON 数据时包含数字?
- binance - 如果我没有使用 Binance API 完全完成订单,如何获取
- regex - HTACCESS:在正则表达式的帮助下替换 URL
- python - 如何将打印和输入堆叠在同一行
- javascript - 如何使用客户端事件 API 在 elFinder 中记录已删除的文件名?
- python - 尝试使用小数包设置精度但无法获得所需的精度
- spring-boot - 如何在 webflux 中抛出异常或处理过滤条件?
- python - 使用 pandas dateoffset 并向前推进 num_years(由列给出)
- r - 如何将同名(STATE)的行转换为R中的列
- c++ - 在向量上使用 push_back()
>