WordPress at Your Fingertips

set_theme_mod() WP 1.0

Update theme modification value for the current theme.

1 time — 0.000983 sec (slow) | 50000 times — 4.90 sec (fast)
Hooks from the function
Return

true|false. True if the value was updated, false otherwise.

Usage

set_theme_mod( $name, $value );
$name(string) (required)
Theme modification name.
$value(mixed) (required)
Theme modification value.

Changelog

Since 2.1.0 Introduced.
Since 5.6.0 A return value was added.

Code of set_theme_mod() WP 5.8.1

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 string $value     The new value of the theme modification.
	 * @param string $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 );
}

Theme Modification API (theme mods options settings)

Other Theme Functions

No comments
    Log In