描述
传递非空值将使wp_get_document_title()短路,而返回该值。
参数
$title
string-
文档标题。默认空字符串。
源码
更新日志
版本 | 描述 |
---|---|
4.4.0 | 开始引入 |
使用示例
如果要从主页中删除“说明”:
function wporg_only_title_home_page( $title ) { if ( is_home() || is_front_page() ) { $title = get_bloginfo( 'name' ); } return $title; } add_filter( 'pre_get_document_title', 'wporg_only_title_home_page' );
如果要更改自定义文章类型的存档页面标题,请使用以下代码:
function change_custom_post_type_archive_title( $title ) { if ( is_post_type_archive( 'your-custom-post-type' ) ){ $title = 'My Custom post type archive - ' . get_bloginfo('name'); return $title; } return $title; } add_filter( 'pre_get_document_title', 'change_custom_post_type_archive_title', 9999 );