set_theme_mod() WordPress Function
The set_theme_mod() function allows you to set a custom value for a specific theme mod. A theme mod is a custom setting that can be controlled from the WordPress Theme Customizer.
set_theme_mod( string $name, mixed $value ) #
Updates theme modification value for the active theme.
Parameters
- $name
(string)(Required)Theme modification name.
- $value
(mixed)(Required)Theme modification value.
Return
(bool) True if the value was updated, false otherwise.
Source
File: wp-includes/theme.php
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | 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 ); } |
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.6.0 | A return value was added. |
2.1.0 | Introduced. |