set_theme_mod

Update theme modification value for the current theme.

Description

set_theme_mod( (string) $name, (mixed) $value ); 

Parameters (2)

0. $name (string)
Theme modification name.
1. $value (mixed)
Theme modification value.

Usage

  1. if ( !function_exists( 'set_theme_mod' ) ) { 
  2. require_once ABSPATH . WPINC . '/theme.php'; 
  3.  
  4. // Theme modification name. 
  5. $name = ''; 
  6.  
  7. // Theme modification value. 
  8. $value = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = set_theme_mod($name, $value); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/theme.php  
  1. function set_theme_mod( $name, $value ) { 
  2. $mods = get_theme_mods(); 
  3. $old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false; 
  4.  
  5. /** 
  6. * Filters the theme mod value on save. 
  7. * The dynamic portion of the hook name, `$name`, refers to the key name of 
  8. * the modification array. For example, 'header_textcolor', 'header_image',  
  9. * and so on depending on the theme options. 
  10. * @since 3.9.0 
  11. * @param string $value The new value of the theme mod. 
  12. * @param string $old_value The current value of the theme mod. 
  13. */ 
  14. $mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value ); 
  15.  
  16. $theme = get_option( 'stylesheet' ); 
  17. update_option( "theme_mods_$theme", $mods );