after_switch_theme action-hookWP 3.3.0

Fires on the next WP load after the theme has been switched.

The parameters differ according to whether the old theme exists or not. If the old theme is missing, the old name will instead be the slug of the old theme.

See switch_theme.

Usage

add_action( 'after_switch_theme', 'wp_kama_after_switch_theme_action', 10, 2 );

/**
 * Function for `after_switch_theme` action-hook.
 * 
 * @param string   $old_name  Old theme name.
 * @param WP_Theme $old_theme WP_Theme instance of the old theme.
 *
 * @return void
 */
function wp_kama_after_switch_theme_action( $old_name, $old_theme ){

	// action...
}
$old_name(string)
Old theme name.
$old_theme(WP_Theme)
WP_Theme instance of the old theme.

Changelog

Since 3.3.0 Introduced.

Where the hook is called

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

Where the hook is used in WordPress

wp-includes/default-filters.php 359
add_action( 'after_switch_theme', '_wp_menus_changed' );
wp-includes/default-filters.php 360
add_action( 'after_switch_theme', '_wp_sidebars_changed' );
wp-includes/theme.php 3476
remove_action( 'after_switch_theme', '_wp_menus_changed' );
wp-includes/theme.php 3477
remove_action( 'after_switch_theme', '_wp_sidebars_changed' );