# Email Alert When the Theme Is Changed

> Emails the site admin whenever someone switches the active theme, with who did it and the old and new theme, so unexpected design changes are caught immediately.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, alerts, themes
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-alert-theme-switch/

## Code

```php
add_action( 'switch_theme', function ( $new_name, $new_theme, $old_theme ) {
    $user = wp_get_current_user();

    wp_mail(
        get_option( 'admin_email' ),
        sprintf( '[%s] Theme changed to %s', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $new_name ),
        sprintf(
            "The active theme was changed from \"%s\" to \"%s\" by %s on %s.\n\nThemes: %s",
            $old_theme instanceof WP_Theme ? $old_theme->get( 'Name' ) : 'unknown',
            $new_name,
            $user->exists() ? $user->user_login : 'an automated process',
            wp_date( 'Y-m-d H:i' ),
            admin_url( 'themes.php' )
        )
    );
}, 10, 3 );
```

## Notes

Theme updates do not trigger it, only switching to a different theme.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Email Alert When the Theme Is Changed" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
