4

Can someone tell me how to remove site name from the email subject.

As of now my email subject looks like this:

[sitename] - Subject goes here

I want it to look like this:

Subject goes here

I checked the wp_mail() code. There is a wp_mail filter available.

Can someone tell me how to use that filter to alter my email subject?

2 Answers 2

7

Finally, I wrote some code and it worked very well.

I hope it helps.

Put this in your functions.php file

//remove sitename from email subject
add_filter('wp_mail', 'email_subject_remove_sitename');
function email_subject_remove_sitename($email) {
  $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  $email['subject'] = str_replace("[".$blogname."] - ", "", $email['subject']);    
  $email['subject'] = str_replace("[".$blogname."]", "", $email['subject']);
  return $email;
}
1
  • I have done same but when I had replace the blogname , somehow its prepend again, so I had to enter another name inside it. check below code , it might help you function email_subject_remove_sitename($email) { $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $email['subject'] = str_replace("[".$blogname."] - ", "", $email['subject']); $email['subject'] = str_replace("[".$blogname."]", "", $email['subject']); $email['subject'] = "NewName | ".$email['subject']; return $email; } Oct 26, 2021 at 3:35
0

That file didnt work for me I had to it in wp-includes/pluggable.php

if ( isset( $atts['message'] ) ) {
    //$message = $atts['message'];
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  $subject = str_replace("[".$blogname."] - ", "", $subject);    
  $subject = str_replace("[".$blogname."]", "", $subject);
}
1
  • 3
    Please don't say you edited a core file.
    – kaiser
    Sep 12, 2014 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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