我使用get\\u the\\u archive\\u title hook添加到我的博客标签和类别归档页面的链接。
https://developer.wordpress.org/reference/hooks/get_the_archive_title/
我只需获取标题并对其进行过滤,将其包含到如下标题中:
我怎样才能避免这个??非常感谢。
我使用get\\u the\\u archive\\u title hook添加到我的博客标签和类别归档页面的链接。
https://developer.wordpress.org/reference/hooks/get_the_archive_title/
我只需获取标题并对其进行过滤,将其包含到如下标题中:我怎样才能避免这个??非常感谢。
您可以这样做来查看它的调用来源:
add_filter("get_the_archive_title", function($val) {
$backtrace = debug_backtrace();
foreach($backtrace as $level) {
if(array_key_exists("file", $level) && preg_match("!that-file\\.php$!", $level["file"]) && array_key_exists("function", $level) && $level["function"] == "get_the_archive_title" ) {
return "works: $val";
}
}
return "test: $val";
}, 10, 1);
您必须使regexp(“that file.php”)适应您的需要,如果没有完成,则可能需要检查另一个函数get_the_archive_title()
.我使用的是shortcode,我想通过使用自定义表从数据库中设置值来更改标题。我已尝试使用\\u标题过滤器,如下所示add_filter(\'the_title\',\'set_page_title\', 10, 2); function set_page_title($title, $id){ if(in_the_loop()) { return \'sdfdsfdsf\'; } return $title;