我有一个运行良好的自定义帖子类型,但是页面中的某些文本对于每个帖子都是相同的,因此我想使用函数将其添加。
我有这样的设置:
function new_default_content($content) {
global $post;
if ($post->post_type == 'custom-post-type') {
$content = 'Test text here';
}
return $content;
}
add_filter('the_content', 'new_default_content');
但是,当我刷新页面时,我只会看到“此处的文字测试”,而不是帖子的内容(来自the_content)。
如果我注释掉此功能,则重新显示帖子内容。我究竟做错了什么?