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

apply_filters( 'document_title_parts', array $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 3 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 "788979883a3d7386e49147b1228f9a62" 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

titlemore...


参数

$titlearray
文档标题部分.

  • title string
    被浏览的页面的标题。
  • page string
    可选的,页码(如果已分页)。
  • tagline string
    可选的,主页上的站点描述。
  • site string
    可选的,不在主页上时的网站标题。


源码

查看源码 官方文档


更新日志

版本描述
4.4.0开始引入

使用示例

  • 示例1

    更改特定页面ID的标题:

    add_filter( 'document_title_parts', function( $title_parts_array ) {
        if ( get_the_ID() == 2055 ) {
            $title_parts_array['title'] = 'Custom Page Title';
        }
        return $title_parts_array;
    } );
  • 示例2

    如果为模板文件添加标题过滤器,请确保add_filter()在模板文件中的get_header()之前。

    <?php
    
    // This filter must be above get_header() to work correctly
    add_filter('document_title_parts', 'callbackFunctionName');
    
    get_header();
    
    ...