set_theme_mod

函式
set_theme_mod ( $name, $value )
引數
  • (string) $name Theme modification name.
    Required:
  • (mixed) $value Theme modification value.
    Required:
返回值
  • (bool) True if the value was updated, false otherwise.
定義位置
相關方法
get_theme_modget_theme_modsremove_theme_modget_theme_dataget_theme_root
引入
2.1.0
棄用
-

set_theme_mod: 這是一個WordPress的函式,設定一個主題的修改。它通常用在主題的 functions.php 檔案中,用於定製主題設定,如網站標題或標誌: 這個函式需要兩個引數:主題修改的名稱和要設定的值。

更新活動主題的主題修改值。

function set_theme_mod( $name, $value ) {
	$mods      = get_theme_mods();
	$old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false;

	/**
	 * Filters the theme modification, or 'theme_mod', value on save.
	 *
	 * 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 3.9.0
	 *
	 * @param mixed $value     The new value of the theme modification.
	 * @param mixed $old_value The current value of the theme modification.
	 */
	$mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value );

	$theme = get_option( 'stylesheet' );

	return update_option( "theme_mods_$theme", $mods );
}

常見問題

FAQs
檢視更多 >