函数原型
get_theme_mod( string $name, mixed $default = false ): mixed
函数描述
Retrieves theme modification value for the active theme.
是否弃用
未弃用
函数参数
-
$name
string
Required - Theme modification name.
-
$default
mixed
Optional - Theme modification default value.
Default:
false
函数返回值
mixed Theme modification value.
函数位置
File: wp-includes/theme.php.
函数源码
function get_theme_mod( $name, $default = false ) {
$mods = get_theme_mods();
if ( isset( $mods[ $name ] ) ) {
/**
* Filters the theme modification, or 'theme_mod', value.
*
* The dynamic portion of the hook name, `$name`, refers to the key name
* of the modification array. For example, 'header_textcolor', 'header_image',
* and so on depending on the theme options.
*
* @since 2.2.0
*
* @param mixed $current_mod The value of the active theme modification.
*/
return apply_filters( "theme_mod_{$name}", $mods[ $name ] );
}
if ( is_string( $default ) ) {
// Only run the replacement if an sprintf() string format pattern was found.
if ( preg_match( '#(?<!%)%(?:\d+\$?)?s#', $default ) ) {
// Remove a single trailing percent sign.
$default = preg_replace( '#(?<!%)%$#', '', $default );
$default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
}
}
/** This filter is documented in wp-includes/theme.php */
return apply_filters( "theme_mod_{$name}", $default );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |

