Using WordPress ‘remove_theme_mods()’ PHP function

The remove_theme_mods() WordPress PHP function removes all theme modification options for the currently active theme.

Usage

To use the remove_theme_mods() function, simply call it without any parameters:

remove_theme_mods();

Parameters

  • None

More information

See WordPress Developer Resources: remove_theme_mods

Examples

Resetting Theme Modifications

If you want to reset all theme modifications to their default values, you can use the remove_theme_mods() function.

// Reset all theme modifications to default values
remove_theme_mods();

Remove Theme Modifications Before Switching Themes

If you want to remove all theme modifications before switching to a new theme, you can use the remove_theme_mods() function in combination with the switch_theme action hook.

function my_theme_cleanup() {
    // Remove all theme modifications before switching themes
    remove_theme_mods();
}
add_action('switch_theme', 'my_theme_cleanup');

Remove Theme Modifications on Plugin Activation

If you want to remove all theme modifications when a specific plugin is activated, use the remove_theme_mods() function with the register_activation_hook() function.

function my_plugin_activation() {
    // Remove all theme modifications when the plugin is activated
    remove_theme_mods();
}
register_activation_hook(__FILE__, 'my_plugin_activation');

Remove Theme Modifications on Admin Init

If you want to remove theme modifications only when an administrator visits the dashboard, use the remove_theme_mods() function with the admin_init action hook.

function my_admin_init() {
    // Remove all theme modifications when an administrator visits the dashboard
    remove_theme_mods();
}
add_action('admin_init', 'my_admin_init');

Remove Theme Modifications with a Custom Function

You can create a custom function to remove theme modifications and call it when needed.

function my_custom_remove_theme_mods() {
    // Remove all theme modifications
    remove_theme_mods();
}

// Call the custom function when needed
my_custom_remove_theme_mods();