Php wp_标题过滤器对<;标题>;标签
我刚刚在我的主题Php wp_标题过滤器对<;标题>;标签,php,html,wordpress,Php,Html,Wordpress,我刚刚在我的主题functions.php文件中添加了以下过滤器: function change_the_title() { return 'My modified title'; } add_filter('wp_title', 'change_the_title'); 在我的header.php中: <!DOCTYPE html> <html <?php language_attributes(); ?>> <head> &
functions.php
文件中添加了以下过滤器:
function change_the_title() {
return 'My modified title';
}
add_filter('wp_title', 'change_the_title');
在我的header.php
中:
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta id="viewport" name="viewport" content="width=device-width">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php wp_head(); ?>
</head>
<body <?php body_class();?>>
您的头
标记中缺少标题
,请添加
标记
您的wp\u过滤器将正常工作。不确定是否需要注入变量,但请尝试此操作
function change_the_title($title) {
return 'My modified title';
}
add_filter('wp_title', 'change_the_title');
我终于发现WordPress的核心代码被更改了,请参阅下面的代码
/**
* Displays title tag with content.
*
* @ignore
* @since 4.1.0
* @since 4.4.0 Improved title output replaced `wp_title()`.
* @access private
*/
function _wp_render_title_tag() {
if ( ! current_theme_supports( 'title-tag' ) ) {
return;
}
echo '<title>' . wp_get_document_title() . '</title>' . "\n";
}
二,。筛选标题部分:
有关更多信息,请参见此处的详细信息:
PS:查看函数wp\u get\u document\u title
的源代码是个好主意,其中的钩子说明了很多
谢谢,但我最终自己找到了解决方案。我们不需要这样做,因为核心函数wp\u head()
将进行注入。谢谢,但我最终自己找到了解决方案。太好了,我不知道:)谢谢@fish\u ball这是完美的答案。最后!关于这个话题的每一篇文章都是错误的——太棒了!谢谢男人。。。有时候我讨厌WordPress。为什么这么难找到呢?@JonathanGruber成为一个贡献者,投票给我,然后你会再次爱上它,哈哈@Adeel我认为主题必须使用新功能添加主题支持('title tag')
而不是旧功能wp\u title
add_filter('pre_get_document_title', 'change_the_title');
function change_the_title() {
return 'The expected title';
}
add_filter('document_title_parts', 'filter_title_part');
function filter_title_part($title) {
return array('a', 'b', 'c');
}