do_action( ‘after_switch_theme’, string $old_name, WP_Theme $old_theme )

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


Old theme name.
WP_Theme instance of the old theme.

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.


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



User Contributed Notes

  1. Skip to note 4 content

    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.