新版wordpress删除wp_head()中title标签并自定义title显示内容

作者: 站长 上传时间: 浏览: N/A 下载: N/A 格式: N/A 评分: N/A

为什么要删除,因为我要自定义,如果要SEO,你可能需要对标题进行好好处理
有两种方式
方式1,删除后自己写一个functions来实现title显示,然后在模版中调用
//删除wp_head()中的title标签
remove_action( 'wp_head', '_wp_render_title_tag', 1 );

后面步骤…自定义标签的函数…自己写,想怎么写怎么写,然后主题中函数调用

方式2,直接重写
add_filter( 'get_the_archive_title', function ($title) {

if ( is_category() ) {

$title = single_cat_title( '', false );

} elseif ( is_tag() ) {

$title = single_tag_title( '', false );

} elseif ( is_author() ) {

$title = '' . get_the_author() . '' ;

}

return $title;

});

Leave a Comment