get_theme_mod

函式
get_theme_mod ( $name, $default = false )
引數
  • (string) $name Theme modification name.
    Required:
  • (mixed) $default Optional. Theme modification default value. Default false.
    Required:
    Default: false
返回值
  • (mixed) Theme modification value.
定義位置
相關方法
get_theme_modsset_theme_modget_themeget_theme_rootget_theme_data
引入
2.1.0
棄用
-

get_theme_mod: 這個函式用來檢索一個主題修改設定值。它接受兩個引數:修改設定的名稱和一個預設值(如果修改設定不存在)。

為活動主題檢索主題修改值。

如果修改名稱不存在,並且`$default`是一個字串,那麼預設值將通過{@link sprintf()}PHP函式傳遞,模板目錄URI作為第一個值,樣式表目錄URI作為第二個值。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >