Prefix WPForms Notification Subjects
Adds the form name and the submitter's name to the subject of WPForms notifications, so messages are easy to tell apart and filter in your inbox.
Opens WPIDE on
Code
$wpide_wpf_subject_format = '[%1$s] %2$s – '; // %1$s form title, %2$s submitter name.
add_filter( 'wpforms_entry_email_atts', function ( $email, $fields, $entry, $form_data ) use ( $wpide_wpf_subject_format ) {
$name = '';
foreach ( (array) $fields as $field ) {
if ( isset( $field['type'] ) && 'name' === $field['type'] && ! empty( $field['value'] ) ) {
$name = (string) $field['value'];
break;
}
}
$title = isset( $form_data['settings']['form_title'] ) ? $form_data['settings']['form_title'] : '';
$email['subject'] = trim( sprintf( $wpide_wpf_subject_format, $title, $name ) ) . ' ' . $email['subject'];
return $email;
}, 10, 4 );
Notes
Uses the first Name field of the form; change the format at the top.
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.