do_action( 'after_switch_theme', string $old_name, WP_Theme $old_theme )

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


Description

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’.


Top ↑

Parameters

$old_name string
Old theme name.
$old_theme WP_Theme
WP_Theme instance of the old theme.

Top ↑

More Information

Callback functions attached to this hook are only triggered in the theme (and/or child theme) being activated. To do things when your theme is deactivated, use switch_theme.


Top ↑

Source

File: wp-includes/theme.php. View all references

do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme );


Top ↑

Changelog

Changelog
Version Description
3.3.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Steven Lin

    Example migrated from Codex:

    Add options for your theme and set them to their default values.

    add_action('after_switch_theme', 'mytheme_setup_options');
    
    function mytheme_setup_options () {
      add_option('mytheme_enable_catalog', 0);
      add_option('mytheme_enable_features', 0);
    }
  2. Skip to note 2 content
    Contributed by NateWr

    Update the default medium image size when a theme is activated.

    function example_update_default_image_size( $old_theme_name, $old_theme = false ) {
    	update_option( 'medium_size_w', 800 );
    	update_option( 'medium_size_h', 400 );
    }
    add_action( 'after_switch_theme', 'example_update_default_image_size', 10, 2 );

You must log in before being able to contribute a note or feedback.