Why does get_theme_mod return blank (or default value) but get_option returns saved value?

This is original code from wordpress:

function get_theme_mods()
{
    $theme_slug = get_option('stylesheet');
    $mods = get_option("theme_mods_$theme_slug");
    if (false === $mods)
    {
        $theme_name = get_option('current_theme');
        if (false === $theme_name)
            $theme_name = wp_get_theme()->get('Name');
        $mods = get_option("mods_$theme_name"); // Deprecated location.
        if (is_admin() && false !== $mods)
        {
            update_option("theme_mods_$theme_slug", $mods);
            delete_option("mods_$theme_name");
        }
    }

    return $mods;
}

function get_theme_mods()
{
    $theme_slug = get_option('stylesheet');
    $mods = get_option("theme_mods_$theme_slug");
    if (false === $mods)
    {
        $theme_name = get_option('current_theme');
        if (false === $theme_name)
            $theme_name = wp_get_theme()->get('Name');
        $mods = get_option("mods_$theme_name"); // Deprecated location.
        if (is_admin() && false !== $mods)
        {
            update_option("theme_mods_$theme_slug", $mods);
            delete_option("mods_$theme_name");
        }
    }

    return $mods;
}

As you can see get_theme_mods uses get_option, but it does not use your key that you provided to save your data with, instead it uses your theme name as a key to fetch or save your theme data. Now if you fetch data with get_theme_mod() it will first get_option("theme_mods_$yourthemename") and then it parses the returned value where your saved theme options actually are.

Leave a Comment