函数文档

display_header_text()

💡 云策文档标注

概述

display_header_text() 函数用于判断是否显示自定义标题文本,基于主题支持和文本颜色设置。

关键要点

  • 检查主题是否支持 'custom-header' 和 'header-text' 功能
  • 通过 get_theme_mod() 获取 'header_textcolor' 值,若为 'blank' 则不显示文本
  • 返回布尔值,指示是否应显示标题文本

代码示例

function display_header_text() {
    if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) {
        return false;
    }

    $text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) );
    return 'blank' !== $text_color;
}

注意事项

  • 函数自 WordPress 3.4.0 版本引入
  • 相关函数包括 get_theme_support(), get_theme_mod(), current_theme_supports()
  • 在 Custom_Image_Header 类中用于自定义标题图像页面的步骤

📄 原文内容

Whether to display the header text.

Return

bool

Source

function display_header_text() {
	if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) {
		return false;
	}

	$text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) );
	return 'blank' !== $text_color;
}

Changelog

Version Description
3.4.0 Introduced.