wordpress在<?php wp_head(); ?>中默认提供了一个title显示方法,如果我们要SEO的话需要对标题进行好好处理。
首先删除wp_head()中的title标签,如下:
1 | remove_action( 'wp_head', '_wp_render_title_tag', 1 ); |
然后自己写一个functions来实现title显示,在模版中调用即可。
我们也可以直接重写来自定义title,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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; }); |