wp_mail_from_name

Home » Hooks » wp_mail_from_name

The wp_mail_from_name hook is used to filter the name that appears in the "From" field of emails sent by WordPress using the wp_mail() function. By default, this field will display the site title. However, using this hook, developers can change it to display any name they want.

This is especially helpful for WordPress websites that send a lot of automated emails, such as password reset emails or email notifications for new comments. By customizing the "From" name, the emails will appear more personalized and trustworthy to the recipients.

Here is an example usage code:

function my_custom_mail_from_name( $from_name ) {
    return 'My Website Name';
}
add_filter( 'wp_mail_from_name', 'my_custom_mail_from_name' );

In this code, we’ve created a custom function called my_custom_mail_from_name. This function takes the existing $from_name parameter and replaces it with "My Website Name". We then use the add_filter() function to hook our custom function into the wp_mail_from_name filter.

This will ensure that all emails sent by WordPress through the wp_mail() function will display "My Website Name" as the sender name instead of the default site title.

Learn More on WordPress.org

WordPress snippets using the wp_mail_from_name hook

Register an account to save your snippets or go Pro to get more features.