get_theme_mod

Retrieve theme modification value for the current theme.

Description

(string) get_theme_mod( (string) $name, (bool) $default = false ); 

If the modification name does not exist, then the $default will be passed through PHP function with the first string the template directory URI and the second string the stylesheet directory URI.

Returns (string)

Parameters (2)

0. $name (string)
Theme modification name.
1. $default — Optional. (bool) => false
The default.

Usage

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

Defined (1)

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

/wp-includes/theme.php  
  1. function get_theme_mod( $name, $default = false ) { 
  2. $mods = get_theme_mods(); 
  3.  
  4. if ( isset( $mods[$name] ) ) { 
  5. /** 
  6. * Filters the theme modification, or 'theme_mod', value. 
  7. * The dynamic portion of the hook name, `$name`, refers to 
  8. * the key name of the modification array. For example,  
  9. * 'header_textcolor', 'header_image', and so on depending 
  10. * on the theme options. 
  11. * @since 2.2.0 
  12. * @param string $current_mod The value of the current theme modification. 
  13. */ 
  14. return apply_filters( "theme_mod_{$name}", $mods[$name] ); 
  15.  
  16. if ( is_string( $default ) ) 
  17. $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); 
  18.  
  19. /** This filter is documented in wp-includes/theme.php */ 
  20. return apply_filters( "theme_mod_{$name}", $default );