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

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


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.

Top ↑



(string) Old theme name.


(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 ↑


File: wp-includes/theme.php

View on Trac

Top ↑


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.