I have been attempting to create a theme reset button for the theme customizer that automatically removes all of the theme_mod settings. I have tried multiple ways to do this and have never been able to get it to work. As seen here.

After multiple failed attempts using the remove_theme_mods approach I begin to wonder if that is my problem other than the ajax and javascript being faulty and not properly binding the button.

Since I save all defaults into one big array so when my theme is installed it automatically has values populated on the theme customizer page, and the theme has a specific look… I was thinking I could try a different approach to instead remove the theme settings I just over ride them, maybe with a custom control? Possibly by somehow assigning these default values to all settings? I really hope someone can help me get this going. If you have any ideas I would appreciate it very very much.

Here is an example of how I assign the default values for the theme:

function newtheme_get_theme_mods() {

$defaults = array(

        'newtheme_responsive'                 => true,

        'newtheme_hero_title'                 => 'Beautiful and Elegant',

        'newtheme_hero_description'           => 'The best theme in the world',

                'newtheme_header_logo'                => '/wp-content/themes/newtheme/img/logo.png',

                'newtheme_header_background_color'    => 'rgba(35,35,35, 0.9)'


    return $defaults;

}

4 Answers
4

There is a function called remove_theme_mods that will kill all theme mods. Beware, however, that this will not only remove the mods that you have defined in your theme using the customizer API. It will also target other mods, such as the menu locations. Widget positions are currently defined as options, not as mods, but this may change in the future. WordPress is likely to move more stuff from options to mods, making remove_theme_mods all the more dangerous to use.

The best approach is to arrange all mods that belong to the theme proper in an array. You can then loop through that array and remove the individual mods with remove_theme_mod.

Leave a Reply

Your email address will not be published. Required fields are marked *