我使用wordpress 2013模板创建了一个子主题。
我想在the_content()之后添加一些内容,所以我做了一个像这样的过滤器:
function bluebaronhomepage(){
$content .= '<h1>hello from extra content</h1>';
return $content;
}....
add_filter('the_content', 'bluebaronhomepage');
这会覆盖页面中的内容,只显示“你好......”。我希望它能在最后附上你好的内容
答案 0 :(得分:2)
您的过滤器应以$content
作为参数:
function bluebaronhomepage($content){
$content .= '<h1>hello from extra content</h1>';
return $content;
}
add_filter('the_content', 'bluebaronhomepage');
在您发布的代码中,$content
未定义,然后您将其设置为<h1>...
。当您返回该字符串时,您将覆盖所有内容。
答案 1 :(得分:0)
您应该通过参数将内容传递给过滤器:
function bluebaronhomepage($content = ''){
$content .= '<h1>hello from extra content</h1>';
return $content;
}....
add_filter('the_content', 'bluebaronhomepage');
您可以在WordPress Codex
了解有关此过滤器的更多信息