检索当前主题的主题修改值。
原型
get_theme_mod( string $name, bool|string $default = false )
描述
如果修改名称不存在,那么$ default将通过sprintf()PHP函数传递,第一个字符串是模板目录URI,第二个字符串是样式表目录URI。
参数
$name
(string)
(Required)
主题修改名称。
$default
(bool|string)
(Optional)
返回值
(string)
源文件
路径:wp-includes/theme.php
<?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 string $current_mod The value of the current theme modification.
*/
return apply_filters( "theme_mod_{$name}", $mods[$name] );
}
if ( is_string( $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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_theme_mod/