Remove the [Site Name] Prefix From Email Subjects
Strips the "[Your Site Name]" WordPress puts at the start of its email subjects, which looks dated and wastes space on phones.
Opens WPIDE on
Code
add_filter( 'wp_mail', function ( $atts ) {
$prefix = '[' . wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) . ']';
if ( 0 === strpos( (string) $atts['subject'], $prefix ) ) {
$atts['subject'] = ltrim( substr( $atts['subject'], strlen( $prefix ) ) );
}
return $atts;
}, 1 );
Notes
Only removes the prefix when it matches your site title exactly.
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.