Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wp_标题过滤器对<;标题>;标签_Php_Html_Wordpress - Fatal编程技术网

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');
}