Action hook 'switch_theme'

in WP Core File wp-includes/theme.php at line 878

View Source

switch_theme

Action Hook
Description
Fires after the theme is switched. See {@see 'after_switch_theme'}.

Hook Information

File Location wp-includes/theme.php View on GitHub
Hook Type Action
Line Number 878

Hook Parameters

Type Name Description
string $new_name Name of the new theme.
WP_Theme $new_theme WP_Theme instance of the new theme.
WP_Theme $old_theme WP_Theme instance of the old theme.

Usage Examples

Basic Usage
<?php
// Hook into switch_theme
add_action('switch_theme', 'my_custom_function', 10, 3);

function my_custom_function($new_name, $new_theme, $old_theme) {
    // Your custom code here
}

Source Code Context

wp-includes/theme.php:878 - How this hook is used in WordPress core
<?php
 873  	 *
 874  	 * @param string   $new_name  Name of the new theme.
 875  	 * @param WP_Theme $new_theme WP_Theme instance of the new theme.
 876  	 * @param WP_Theme $old_theme WP_Theme instance of the old theme.
 877  	 */
 878  	do_action( 'switch_theme', $new_name, $new_theme, $old_theme );
 879  }
 880  
 881  /**
 882   * Checks that the active theme has the required files.
 883   *

PHP Documentation

<?php
/**
	 * Fires after the theme is switched.
	 *
	 * See {@see 'after_switch_theme'}.
	 *
	 * @since 1.5.0
	 * @since 4.5.0 Introduced the `$old_theme` parameter.
	 *
	 * @param string   $new_name  Name of the new theme.
	 * @param WP_Theme $new_theme WP_Theme instance of the new theme.
	 * @param WP_Theme $old_theme WP_Theme instance of the old theme.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 3
  • File: wp-includes/theme.php
Related Hooks

Related hooks will be displayed here in future updates.