Cyb*_*kie 4 php wordpress function filter
我正在尝试添加代码来the_content()运行.我尝试了以下内容
function add_something($content) {
echo "test";
}
add_filter( 'the_content', 'add_something', 6);
Run Code Online (Sandbox Code Playgroud)
添加过滤器后,我的帖子只返回test没有内容的回声.如何在不省略内容的情况下执行自定义代码?
mar*_*rio 12
我猜测你需要类似的东西(如果它确实是一个过滤器回调):
function add_something($content) {
return "test" . $content;
}
Run Code Online (Sandbox Code Playgroud)
似乎文档说的是:http: //wordpress.org/support/topic/add-something-to-the_content
你省略了return语句.
function add_something($content) {
echo "test";
... change $content ......
return $content;
}
Run Code Online (Sandbox Code Playgroud)
请注意,如果要修改内容,则必须将其附加到变量.使用echo将在调用脚本时输出'test'.它不会附加或添加到the_content()