Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.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_Wordpress_Wordpress Theming - Fatal编程技术网

Php 为什么wp_标题过滤器根本不起作用?

Php 为什么wp_标题过滤器根本不起作用?,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我知道还有其他类似的问题,但没有找到可靠的答案。因此: 首先激活这个东西(简单代码): 其次,从header.php中删除title标记 第三,在页面模板上,在调用get_header()之前,添加如下内容: add_filter('wp_title', 'set_custom_title', 10, 3); function set_custom_title($title, $sep, $seplocation){ return 'test'; } 在任何模板中,无论是页

我知道还有其他类似的问题,但没有找到可靠的答案。因此:

首先激活这个东西(简单代码):

其次,从header.php中删除title标记

第三,在页面模板上,在调用
get_header()
之前,添加如下内容:

  add_filter('wp_title', 'set_custom_title', 10, 3);
  function set_custom_title($title, $sep, $seplocation){
    return 'test';
  }
在任何模板中,无论是页面、归档、自定义分类法还是post类型归档,这都是行不通的。没什么。Wordpress正在自行生成标题

为什么??我做错什么了吗?请注意,这段代码曾经在其他站点/主题中使用过


这可能是wp5.2.0的一个问题吗?

因此,多亏了@Vel,答案是重新添加标题标签(即使在以前的wp版本中>不知道是哪个版本,您不得不从head删除它)

我当前的工作代码:

//functions.php
add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
  add_theme_support('title-tag');
}

//header.php
<title><?php wp_title('|', true, 'right'); ?> | <?php echo get_bloginfo('name') ?></title>

//page templates
$window_title = // do something
add_filter('wp_title', function($title, $sep, $seplocation) use($window_title){ return $window_title; }, 10, 3);
//functions.php
添加动作('after_setup_theme'、'theme_setup');
函数主题_设置(){
添加主题支持(“标题标签”);
}
//header.php
| 
//页面模板
$window\u title=//做点什么
添加过滤器('wp_title',函数($title,$sep,$seplocation)使用($window_title){return$window_title;},10,3);

因此,多亏了@Vel,答案是重新添加标题标签(即使在以前的wp版本中,也不知道您必须从head删除它的版本)

我当前的工作代码:

//functions.php
add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
  add_theme_support('title-tag');
}

//header.php
<title><?php wp_title('|', true, 'right'); ?> | <?php echo get_bloginfo('name') ?></title>

//page templates
$window_title = // do something
add_filter('wp_title', function($title, $sep, $seplocation) use($window_title){ return $window_title; }, 10, 3);
//functions.php
添加动作('after_setup_theme'、'theme_setup');
函数主题_设置(){
添加主题支持(“标题标签”);
}
//header.php
| 
//页面模板
$window\u title=//做点什么
添加过滤器('wp_title',函数($title,$sep,$seplocation)使用($window_title){return$window_title;},10,3);

尝试使用以下代码-

add_filter('document_title_parts', function($titles){
    return array('title' => 'Custom Title');
});

尝试使用以下代码-

add_filter('document_title_parts', function($titles){
    return array('title' => 'Custom Title');
});

对于仍然存在此问题的
wp\u title
过滤器不工作的任何人,我建议添加一个更高的优先级值。较高的优先级值将确保您的过滤器被执行,并且不会被您的主题或安装的插件中的其他过滤器覆盖。请参见以下内容:(参考:)


对于仍然存在此问题的
wp\u title
过滤器不工作的任何人,我建议添加一个更高的优先级值。较高的优先级值将确保您的过滤器被执行,并且不会被您的主题或安装的插件中的其他过滤器覆盖。请参见以下内容:(参考:)


在header.php
|
@Vel中添加此代码,它可以工作,谢谢。但很奇怪,因为很久以前这是一个禁忌。。。你必须删除标题标签从头部,以使过滤器的工作。。。呸..在header.php
|
@Vel中添加此代码,它可以工作,谢谢。但很奇怪,因为很久以前这是一个禁忌。。。你必须删除标题标签从头部,以使过滤器的工作。。。请看我自己的答案。请看我自己的答案。