WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Action Reference/switch theme

Contents

Description

switch_theme is triggered when the blog's theme is changed. Specifically, it fires after the theme has been switched but before the next request. Theme developers should this hook to do things when their theme is deactivated.

Theme functions attached to this hook are only triggered in the theme being deactivated. To do things when your theme is activated, use after_switch_theme.

Functions attached to this action hook receive one parameter: a string with the name of the new theme being activated.

Usage

 <?php add_action('switch_theme''theme_deactivation_function'); ?> 

Examples

Delete a theme's options after deactivation.

add_action('switch_theme', 'mytheme_setup_options');

function mytheme_setup_options () {
  delete_option('mytheme_enable_features');
  delete_option('mytheme_enable_catalog');
}

Source File

switch_theme action hook is located in wp-includes/theme.php

Related

See also