switch_theme WordPress Action Hook

The switch_theme hook is triggered when a user activates a new theme. It allows themes to do any necessary cleanup before the new theme takes over.

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

Fires after the theme is switched.


Parameters

$new_name

(string)Name of the new theme.

$new_theme

(WP_Theme)WP_Theme instance of the new theme.

$old_theme

(WP_Theme)WP_Theme instance of the old theme.


Top ↑

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.

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


Top ↑

Source

File: wp-includes/theme.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
4.5.0Introduced the $old_theme parameter.
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More