get_theme_mod() – Retrieves theme modification value for the active theme.

You appear to be a bot. Output may be restricted

Description

Retrieves theme modification value for the active theme.

If the modification name does not exist and $default is a string, then the default will be passed through the https://www.php.net/sprintf PHP function with the template directory URI as the first value and the stylesheet directory URI as the second value.

Usage

$mixed = get_theme_mod( $name, $default );

Parameters

$name
( string ) required – Theme modification name.
$default
( mixed ) optional – Optional. Theme modification default value. Default false.

Returns

mixed Theme modification value.

Source

File name: wordpress/wp-includes/theme.php
Lines:

1 to 30 of 30
function get_theme_mod( $name, $default = false ) {
  $mods = get_theme_mods();

  if ( isset( $mods[ $name ] ) ) {
    
/**
 * Filters the theme modification, or 'theme_mod', value.
 *
 * 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 2.2.0
 *
 * @param mixed $current_mod The value of the active theme modification.
 */
    return apply_filters( "theme_mod_{$name}", $mods[ $name ] );
  }

  if ( is_string( $default ) ) {
    // Only run the replacement if an sprintf() string format pattern was found.
    if ( preg_match( '#(?<!%)%(?:\d+\$?)?s#', $default ) ) {
      // Remove a single trailing percent sign.
      $default = preg_replace( '#(?<!%)%$#', '', $default );
      $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
    }
  }

  
/** This filter is documented in wp-includes/theme.php */
  return apply_filters( "theme_mod_{$name}", $default );
}
 

 View on GitHub View on Trac