文档标题在\\u wp\\u render\\u title\\u标记中呈现。如果您想修改它,您需要删除WP函数并使用类似的逻辑创建自己的函数。
类似于此:
remove_action(\'wp_head\', \'_wp_render_title_tag\', 1);
然后:
add_filter(\'wp_head\', function () {
if (!current_theme_supports(\'title-tag\')) {
return;
}
if (did_action(\'wp_head\') || doing_action(\'wp_head\') && is_single()) {
$categories = get_the_category();
// Assuming the post has many categories will take the first
$category = reset($categories);
if ($category) {
echo \'<title>\' . $category->name . \' - \' . get_the_title() . \'</title>\' . "\\n";
}
}
echo \'<title>\' . wp_get_document_title() . \'</title>\' . "\\n";
});