Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
pre_get_document_title - 在生成文档标题之前过滤文档标题 - WordPress钩子 - WordPress动力
当前浏览:首页 / WordPress钩子 / pre_get_document_title

apply_filters( 'pre_get_document_title', string $title )

在生成文档标题之前过滤文档标题


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 4 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "75f0fc18d52741442b6994d7d9c58e79" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "422b96c784344dc1934ab28b50af8ac0" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "901a9de269b560520bcd8dd78854aca2" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

document

premore...

titlemore...


描述

传递非空值将使wp_get_document_title()短路,而返回该值。


参数

$titlestring
文档标题。默认空字符串。


源码

查看源码 官方文档


更新日志

版本描述
4.4.0开始引入

使用示例

  • 示例1

    如果要从主页中删除“说明”:

    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' );
  • 示例2

    如果要更改自定义文章类型的存档页面标题,请使用以下代码:

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