我想用Wordpress插件覆盖页面的<title>
标签。 我不想更改主题的代码。我只是想强制主题通过插件更改一些页面标题。使用Wordpress插件覆盖标题标签
主题使用add_theme_support('title-tag')
。请注意,现在不推荐使用wp_title。
我想用Wordpress插件覆盖页面的<title>
标签。 我不想更改主题的代码。我只是想强制主题通过插件更改一些页面标题。使用Wordpress插件覆盖标题标签
主题使用add_theme_support('title-tag')
。请注意,现在不推荐使用wp_title。
您的问题是,如果主题已经支持title-tag
,则不能在主题中使用wp_title()
。你的主题的<head>
应该是这样的:
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php wp_head(); ?>
</head>
过滤器和title-tag
支持:
add_action('after_setup_theme', 'my_theme_functions');
function my_theme_functions() {
add_theme_support('title-tag');
}
add_filter('wp_title', 'custom_titles', 10, 2);
function custom_titles($title, $sep) {
//set custom title here
$title = "Some other title" . $title;;
return $title;
}
如果你这样做,它会很好地工作。
https://codex.wordpress.org/Plugin_API/Filter_Reference/the_title – Scuzzy