after_switch_theme
Action HookDescription
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 {@see 'switch_theme'}.Hook Information
File Location |
wp-includes/theme.php
View on GitHub
|
Hook Type | Action |
Line Number | 3507 |
Hook Parameters
Type | Name | Description |
---|---|---|
string
|
$old_name
|
Old theme name. |
WP_Theme
|
$old_theme
|
WP_Theme instance of the old theme. |
Usage Examples
Basic Usage
<?php
// Hook into after_switch_theme
add_action('after_switch_theme', 'my_custom_function', 10, 2);
function my_custom_function($old_name, $old_theme) {
// Your custom code here
}
Source Code Context
wp-includes/theme.php:3507
- How this hook is used in WordPress core
<?php
3502 * @param WP_Theme $old_theme WP_Theme instance of the old theme.
3503 */
3504 do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme );
3505 } else {
3506 /** This action is documented in wp-includes/theme.php */
3507 do_action( 'after_switch_theme', $stylesheet, $old_theme );
3508 }
3509
3510 flush_rewrite_rules();
3511
3512 update_option( 'theme_switched', false );
PHP Documentation
<?php
/**
* 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 {@see 'switch_theme'}.
*
* @since 3.3.0
*
* @param string $old_name Old theme name.
* @param WP_Theme $old_theme WP_Theme instance of the old theme.
*/
Quick Info
- Hook Type: Action
- Parameters: 2
- File: wp-includes/theme.php
Related Hooks
Related hooks will be displayed here in future updates.