get_theme_mod

The timeline below displays how wordpress function get_theme_mod has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Retrieves theme modification value for the active theme.
 *
 * If the modification name does not exist and `$default_value` is a string, then the
 * default will be passed through the {@link https://www.php.net/sprintf sprintf()}
 * PHP function with the template directory URI as the first value and the
 * stylesheet directory URI as the second value.
 *
 * @since 2.1.0
 *
 * @param string $name          Theme modification name.
 * @param mixed  $default_value Optional. Theme modification default value. Default false.
 * @return mixed Theme modification value.
 */
function get_theme_mod($name, $default_value = 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_value)) {
        // Only run the replacement if an sprintf() string format pattern was found.
        if (preg_match('#(?<!%)%(?:\d+\$?)?s#', $default_value)) {
            // Remove a single trailing percent sign.
            $default_value = preg_replace('#(?<!%)%$#', '', $default_value);
            $default_value = sprintf($default_value, get_template_directory_uri(), get_stylesheet_directory_uri());
        }
    }
    /** This filter is documented in wp-includes/theme.php */
    return apply_filters("theme_mod_{$name}", $default_value);
}

WordPress Version: 6.1

/**
 * 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 {@link https://www.php.net/sprintf sprintf()}
 * PHP function with the template directory URI as the first value and the
 * stylesheet directory URI as the second value.
 *
 * @since 2.1.0
 *
 * @param string $name    Theme modification name.
 * @param mixed  $default Optional. Theme modification default value. Default false.
 * @return mixed Theme modification value.
 */
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);
}

WordPress Version: 5.9

/**
 * Retrieves theme modification value for the current theme.
 *
 * If the modification name does not exist and `$default` is a string, then the
 * default will be passed through the {@link https://www.php.net/sprintf sprintf()}
 * PHP function with the template directory URI as the first value and the
 * stylesheet directory URI as the second value.
 *
 * @since 2.1.0
 *
 * @param string $name    Theme modification name.
 * @param mixed  $default Optional. Theme modification default value. Default false.
 * @return mixed Theme modification value.
 */
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 current 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);
}

WordPress Version: 5.6

/**
 * Retrieves theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link https://www.php.net/sprintf sprintf()} PHP function with
 * the template directory URI as the first string and the stylesheet directory URI
 * as the second string.
 *
 * @since 2.1.0
 *
 * @param string       $name    Theme modification name.
 * @param string|false $default Optional. Theme modification default value. Default false.
 * @return mixed Theme modification value.
 */
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 string $current_mod The value of the current 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);
}

WordPress Version: 5.5

/**
 * Retrieves theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link https://www.php.net/sprintf sprintf()} PHP function with
 * the template directory URI as the first string and the stylesheet directory URI
 * as the second string.
 *
 * @since 2.1.0
 *
 * @param string       $name    Theme modification name.
 * @param string|false $default Optional. Theme modification default value. Default false.
 * @return mixed Theme modification value.
 */
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 string $current_mod The value of the current 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)) {
            $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);
}

WordPress Version: 5.4

/**
 * Retrieve theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link https://www.php.net/sprintf sprintf()} PHP function with
 * the template directory URI as the first string and the stylesheet directory URI
 * as the second string.
 *
 * @since 2.1.0
 *
 * @param string       $name    Theme modification name.
 * @param string|false $default Optional. Theme modification default value. Default false.
 * @return mixed Theme modification value.
 */
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 string $current_mod The value of the current 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)) {
            $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);
}

WordPress Version: 5.3

/**
 * Retrieve theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link https://secure.php.net/sprintf sprintf()} PHP function with
 * the template directory URI as the first string and the stylesheet directory URI
 * as the second string.
 *
 * @since 2.1.0
 *
 * @param string       $name    Theme modification name.
 * @param string|false $default Optional. Theme modification default value. Default false.
 * @return mixed Theme modification value.
 */
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 string $current_mod The value of the current 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)) {
            $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);
}

WordPress Version: 5.1

/**
 * Retrieve theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link https://secure.php.net/sprintf sprintf()} PHP function with the first
 * string the template directory URI and the second string the stylesheet
 * directory URI.
 *
 * @since 2.1.0
 *
 * @param string      $name    Theme modification name.
 * @param bool|string $default
 * @return mixed
 */
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 string $current_mod The value of the current theme modification.
         */
        return apply_filters("theme_mod_{$name}", $mods[$name]);
    }
    if (is_string($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);
}

WordPress Version: 4.6

/**
 * Retrieve theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link https://secure.php.net/sprintf sprintf()} PHP function with the first
 * string the template directory URI and the second string the stylesheet
 * directory URI.
 *
 * @since 2.1.0
 *
 * @param string      $name    Theme modification name.
 * @param bool|string $default
 * @return string
 */
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 string $current_mod The value of the current theme modification.
         */
        return apply_filters("theme_mod_{$name}", $mods[$name]);
    }
    if (is_string($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);
}

WordPress Version: 4.3

/**
 * Retrieve theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link http://php.net/sprintf sprintf()} PHP function with the first
 * string the template directory URI and the second string the stylesheet
 * directory URI.
 *
 * @since 2.1.0
 *
 * @param string      $name    Theme modification name.
 * @param bool|string $default
 * @return string
 */
function get_theme_mod($name, $default = false)
{
    $mods = get_theme_mods();
    if (isset($mods[$name])) {
        /**
         * Filter 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 string $current_mod The value of the current theme modification.
         */
        return apply_filters("theme_mod_{$name}", $mods[$name]);
    }
    if (is_string($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);
}

WordPress Version: 4.1

/**
 * Retrieve theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link http://php.net/sprintf sprintf()} PHP function with the first
 * string the template directory URI and the second string the stylesheet
 * directory URI.
 *
 * @since 2.1.0
 *
 * @param string $name Theme modification name.
 * @param bool|string $default
 * @return string
 */
function get_theme_mod($name, $default = false)
{
    $mods = get_theme_mods();
    if (isset($mods[$name])) {
        /**
         * Filter 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 string $current_mod The value of the current theme modification.
         */
        return apply_filters("theme_mod_{$name}", $mods[$name]);
    }
    if (is_string($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);
}

WordPress Version: 3.8

/**
 * Retrieve theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link http://php.net/sprintf sprintf()} PHP function with the first
 * string the template directory URI and the second string the stylesheet
 * directory URI.
 *
 * @since 2.1.0
 *
 * @param string $name Theme modification name.
 * @param bool|string $default
 * @return string
 */
function get_theme_mod($name, $default = false)
{
    $mods = get_theme_mods();
    if (isset($mods[$name])) {
        /**
         * Filter 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 string $current_mod The value of the current theme modification.
         */
        return apply_filters("theme_mod_{$name}", $mods[$name]);
    }
    if (is_string($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);
}

WordPress Version: 3.7

/**
 * Retrieve theme modification value for the current theme.
 *
 * If the modification name does not exist, then the $default will be passed
 * through {@link http://php.net/sprintf sprintf()} PHP function with the first
 * string the template directory URI and the second string the stylesheet
 * directory URI.
 *
 * @since 2.1.0
 * @uses apply_filters() Calls 'theme_mod_$name' filter on the value.
 *
 * @param string $name Theme modification name.
 * @param bool|string $default
 * @return string
 */
function get_theme_mod($name, $default = false)
{
    $mods = get_theme_mods();
    if (isset($mods[$name])) {
        return apply_filters("theme_mod_{$name}", $mods[$name]);
    }
    if (is_string($default)) {
        $default = sprintf($default, get_template_directory_uri(), get_stylesheet_directory_uri());
    }
    return apply_filters("theme_mod_{$name}", $default);
}