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.
Opens WPIDE on
Code
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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.