Title: switch_theme
Published: April 25, 2014
Last modified: August 20, 2026

---

# do_action( ‘switch_theme’, string $new_name, WP_Theme $new_theme, WP_Theme $old_theme )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#user-contributed-notes)

Fires after the theme is switched.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#description)󠁿

See [‘after_switch_theme’](https://developer.wordpress.org/reference/hooks/after_switch_theme/).

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#parameters)󠁿

 `$new_name`string

Name of the new theme.

`$new_theme`[WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/)

[WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/) instance
of the new theme.

`$old_theme`[WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/)

[WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/) instance
of the old theme.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#more-information)󠁿

switch_theme is triggered when the blog’s theme is changed. Specifically, it fires
after the theme has been switched but before the next request. Theme developers 
should use this hook to do things when their theme is deactivated.

Theme functions attached to this hook are only triggered in the theme being deactivated.
To do things when your theme is activated, use [after_switch_theme](https://developer.wordpress.org/reference/hooks/after_switch_theme/).

Functions attached to this action hook receive one parameter: a string with the 
name of the new theme being activated.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#source)󠁿

    ```php
    do_action( 'switch_theme', $new_name, $new_theme, $old_theme );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/theme.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/theme.php#L875)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/theme.php#L875-L875)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#related)󠁿

| Used by | Description | 
| [switch_theme()](https://developer.wordpress.org/reference/functions/switch_theme/)`wp-includes/theme.php` |

Switches the theme.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Introduced the `$old_theme` parameter. | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#comment-content-2441)
 2.    [sarahcoding](https://profiles.wordpress.org/sarahcoding/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/switch_theme/#comment-2441)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_theme%2F%23comment-2441)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_theme%2F%23comment-2441)
 4.  This hook is useful while deactivating a theme.
 5.  For example:
 6.      ```php
         function deactivate_my_theme( $new_theme ) {
         	flush_rewrite_rules(false);
         }
         add_action( 'switch_theme', 'deactivate_my_theme' );
         ```
     
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_theme%2F%3Freplytocom%3D2441%23feedback-editor-2441)
 8.   [Skip to note 4 content](https://developer.wordpress.org/reference/hooks/switch_theme/?output_format=md#comment-content-4451)
 9.    [Collins Mbaka](https://profiles.wordpress.org/collinsmbaka/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/switch_theme/#comment-4451)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_theme%2F%23comment-4451)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_theme%2F%23comment-4451)
 11. Delete a theme’s options after deactivation
 12.     ```php
         add_action('switch_theme', 'mytheme_setup_options');
     
         function mytheme_setup_options () {
           delete_option('mytheme_enable_features');
           delete_option('mytheme_enable_catalog');
         }
         ```
     
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_theme%2F%3Freplytocom%3D4451%23feedback-editor-4451)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fswitch_theme%2F)
before being able to contribute a note or feedback.