customising-default-wordpress-emails-without-plugin

WordPress sends various automated emails, such as registration confirmation, password reset, and comment notification messages, to users and administrators. These default WordPress emails, while functional, often lack a personalised and branded touch. Customising these emails can improve the user experience and reinforce your website’s identity. Here’s how you can do it without relying on a plugin.

Step 1: Create a Child Theme (if not already in use)

Before customising default WordPress emails, it’s a good practice to create a child theme if you haven’t already. A child theme ensures that your customisation won’t be lost when your main theme receives updates. If you’re already using a child theme, you can proceed to the next step.

Step 2: Locate the Email Template Files

Default WordPress email templates are stored in the core files of WordPress, but it’s not advisable to edit these core files directly. Instead, you should copy the relevant email template to your child theme’s directory for customisation. The templates for the most common emails are stored in the pluggable.php file, and you can find them in the functions:

  • Registration Confirmation Email: wp_new_user_notification()
  • Password Reset Email: wp_password_change_notification()
  • Comment Notification Email: wp_notify_postauthor()

Step 3: Copy and Modify the Template

In your child theme directory, create a new folder and name it wp_mail. This directory will hold your customised email templates.

To customise a specific email template, locate the corresponding function in your theme’s functions.php file, copy it, and paste it into your child theme’s functions.php. If the function doesn’t already exist in your theme’s functions.php, you can copy it from the pluggable.php file.

Read: Building Custom Backend Plugins For WordPress

Step 4: Customise the Email Content

With the email template function in your child theme’s functions.php, you can start customising the email’s content. You have the flexibility to modify the email subject, message body, and headers to match your branding and style.

For example, if you want to customise the registration confirmation email, you can do something like this:

function custom_registration_email_subject( $subject ) { return 'Welcome to Our Website!'; } function custom_registration_email_message( $message, $user_id )

{ $user = get_user_by( 'id', $user_id ); $message = "Hello " . $user->user_login . ",\n"; $message .= "Thank you for registering on Our Website. We're thrilled to have you as a member of our community.\n"; $message .= "If you have any questions or need assistance, please don't hesitate to contact us.\n"; $message .= "Best regards,\n"; $message .= "The Our Website Team"; return $message; }

add_filter( 'wp_mail_from', 'custom_registration_email_subject' ); add_filter( 'wp_mail_from_name', 'custom_registration_email_message' );

In this example, we’ve modified the email’s subject and message to make it more personalised and in line with your website’s brand.

Step 5: Test Your Customisation

Testing your customisation is essential to ensure they work correctly. Register a new user, initiate a password reset, or create a test comment to trigger the relevant email notifications. Verify that they reflect your customisation.

Step 6: Keep an Eye on Updates

WordPress core updates may occasionally include changes to email templates. After each update, review your custom email templates to ensure they remain functional and aligned with your branding.

Read: Understanding WordPress User Roles And Capabilities

To Sum Up

By customising default WordPress emails without using a plugin, you can create email notifications that are not only functional but also carry your brand’s identity, enhancing the user experience on your website.

Leave a Reply

Your email address will not be published. Required fields are marked *