【发布时间】:2018-03-15 11:27:43
【问题描述】:
我正在尝试在模板文件中设置简码。
我有以下设置:
作为 WP 页面中的内容:
[test]shortcode![/test]
在functions.php中:
function test( $atts, $content = null ) {
return '<h1>'.$content.'</h1>';
}
add_shortcode("test", "test");
在上面页面的template.php中:
<?php echo do_shortcode('[test]'); ?>
虽然没有返回任何内容。如果我在 template.php 中调用 the_post() 和 the_content() ,短代码确实会正确显示为 h1 但这不是我想要的功能,我需要能够在特定位置插入 [test] 短代码。
此外,我似乎可以在函数中添加硬编码内容并显示它,所以很可能 $content 变量没有返回任何数据?是什么原因造成的?
【问题讨论】:
标签: php wordpress wordpress-theming themes