after_switch_theme

Fires on the first WP load after a theme switch if the old theme still exists.

Description

do_action( 'after_switch_theme', (string) $old_theme_get_name, (WP_Theme) $old_theme ); 

This action fires multiple times and the parameters differs according to the context, if the old theme exists or not. If the old theme is missing, the parameter will be the slug of the old theme.

Parameters (2)

0. $old_theme_get_name (string)
The old theme get name.
1. $old_theme (WP_Theme)
WP_Theme instance of the old theme.

Usage

To run the hook, copy the example below.
  1. // run the action 
  2. do_action( 'after_switch_theme', $old_theme_get_name, $old_theme ); 
The following example is for adding a hook callback.
  1. // define the after_switch_theme callback 
  2. function action_after_switch_theme( $old_theme_get_name, $old_theme ) { 
  3. // make action magic happen here... 
  4. }; 
  5.  
  6. // add the action 
  7. add_action( 'after_switch_theme', 'action_after_switch_theme', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the action 
  2. remove_action( 'after_switch_theme', 'action_after_switch_theme', 10, 2 ); 

Defined (2)

The action is defined in the following location(s).

/wp-includes/theme.php  
  1. do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme ); 
  1. do_action( 'after_switch_theme', $stylesheet );