# Tag Email Subjects on Non-Production Sites

> Adds [STAGING] or [DEVELOPMENT] to the start of every email subject sent from a non-production copy of the site, so nobody confuses test emails with real ones.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, staging, subject
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-environment-subject-tag/

## Code

```php
add_filter( 'wp_mail', function ( $atts ) {
    $env = wp_get_environment_type();

    if ( 'production' !== $env ) {
        $atts['subject'] = '[' . strtoupper( $env ) . '] ' . $atts['subject'];
    }

    return $atts;
} );
```

## Notes

Uses wp_get_environment_type(). Production emails are unchanged.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Tag Email Subjects on Non-Production Sites" 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/
