WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Action Reference/after switch theme

Description

after_switch_theme is triggered on the request immediately following a theme switch.

Theme 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.

Usage

<?php add_action("after_switch_theme", "mytheme_do_something"); ?>

Examples

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);
}

Source File

after_switch_theme action hook is located in wp-includes/theme.php

Related

See Also