get_background_color()
云策文档标注
概述
get_background_color() 函数用于检索 WordPress 主题的自定义背景颜色值。它通过 get_theme_mod() 获取设置,并支持默认值回退。
关键要点
- 函数返回字符串类型的背景颜色值,通常为十六进制代码。
- 内部实现基于 get_theme_mod() 和 get_theme_support(),优先从主题修改中获取,否则使用默认值。
- 自 WordPress 3.0.0 版本引入,是处理自定义背景颜色的核心函数。
代码示例
$background_color = get_background_color();
echo 'Current background color for your theme: #' . $background_color;
原文内容
Retrieves value for custom background color.
Source
function get_background_color() {
return get_theme_mod( 'background_color', get_theme_support( 'custom-background', 'default-color' ) );
}
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
Skip to note 2 content
Codex
Get background color
$background_color = get_background_color(); echo 'Current background color for your theme: #' . $background_color;