If you want to customize the subject line of the emails you receive from your website’s contact form, you can easily do so by editing the contact page template directly from your WordPress Admin Panel. This guide will walk you through the simple steps to set a hardcoded email subject.
1. Access the Theme Editor
- Log in to your WordPress Admin Panel.
- Navigate to the Left Menu and click on Appearance.
- From the dropdown menu, select Theme Editor.Note:
2. Locate the page-contact.php
Template File
- On the right side of the Theme Editor, you’ll see a list of theme files.
- Scroll down to find the
page-templates/page-contact.php
file. - Click on
page-contact.php
to open it in the editor.
3. Find the Email Sending Code
- In the editor, scroll down to locate the line of code that sends the email. You’re looking for a line that contains
wp_mail
. - The code should look like this:
wp_mail( $emailTo, __( '[Contact Form] ', 'tishonator' ).$subject, $body, $headers );
This line sends the email with the subject line that includes[Contact Form]
and the subject entered by the user.
4. Modify the Email Subject to a Hardcoded Value
- To set a fixed subject line for all emails from the contact form, replace the existing
wp_mail
line with the following code:wp_mail( $emailTo, 'New Contact Form Message', $body, $headers );
Replace'New Contact Form Message'
with the exact subject line you want to use.
Example:wp_mail( $emailTo, 'Website Inquiry', $body, $headers );
That’s it. Then simply save changes you made to the file.