WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm able to display a message by activation of my theme with the 'new' after_switch_theme hook this way:

function themeActivationFunction($oldname, $oldtheme=false) {
$msg = '
    <div class="error">
        <p>The ' . get_option( 'current_theme' ) . ' theme has been ACTIVATED.</p>
    add_action( 'admin_notices', $c = create_function( '', 'echo "' . addcslashes( $msg, '"' ) . '";' ) );

add_action("after_switch_theme", "themeActivationFunction", 10 ,  2);

But it does not work with the swith_theme hook for deactivation of my theme. I think because by switching the theme to another one to default WordPress message overwrites my message stucking in the theme that gets deactivated and the reload of the screen deletes everything.

function themeDeactivationFunction($theme) {
// Lets let the admin know whats going on.
        $msg = '
    <div class="error">
        <p>Your theme has been DEACTIVATED</p>
    add_action( 'admin_notices', $c = create_function( '', 'echo "' . addcslashes( $msg, '"' ) . '";' ) );
add_action("switch_theme", "themeDeactivationFunction", 10 , 2);

I'm looking for a 'work around' to notify a user about deactivating my theme and the setup routine after it.

share|improve this question
The messages are just examples. – Paul Geisler Aug 6 '12 at 8:51
up vote 0 down vote accepted

It's impossible, because after deactivation your theme isn't even loaded!

It's possible, but hacky. Essentially, we unset the action param, load in the themes admin page & then exit before the redirect-on-success occurs.

add_action( 'switch_theme', 'wpse_60972_theme_deactivate_message' );
function wpse_60972_theme_deactivate_message()
    $msg = '
    <div class="error">
        <p>Your theme has been DEACTIVATED</p>

    add_action( 'admin_notices', create_function( '', 'echo "' . addcslashes( $msg, '"' ) . '";' ) );

    unset( $_GET['action'] );
    require ABSPATH . 'wp-admin/themes.php';

If the code you posted is verbatim, may I ask why you want do as such? WordPress has it's own notices for activation & deactivation.

share|improve this answer
I have a specific theme that should have specific pages. By activating the theme i check if there are those specific pages. If not, i create them and set some options like show_on_front, page_on_front and page_for_posts. After deactivating my specific theme i want to set the pervious options and notify the user about it. – Paul Geisler Aug 6 '12 at 8:47
That's fine, but why are the activation/deactivation messages necessary? – TheDeadMedic Aug 6 '12 at 8:48
For good UX... feedback is always good for user. :-) – Paul Geisler Aug 6 '12 at 8:49
WordPress displays activation/deactivation messages by default, there's no need for you to replicate this behaviour. – TheDeadMedic Aug 6 '12 at 8:52
Yes, i know. But for activation i want something like My-Theme is activated. Specific pages 'Wellcome' and 'News' were created. 'Wellcome' is now your front page and 'News' your posts page. Your previous settings were saved and will be reset by deactivating this theme. And for deactivation i want something like My-Theme is deactivated. Your previous settings are reseted. You can delete 'Wellcome' and 'News' by clicking here. – Paul Geisler Aug 6 '12 at 9:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.