In my case, i have hid the subject box, and fill it with custom javascript. But if there is an easier way i would be happy to use as well. Just noting here to get notified of Greg’s answer.
You can add post title in the message title by adding following code to your theme functions.php file
add_filter( "adverts_contact_form_email", "contact_form_email", 10, 3 );
function contact_form_email( $mail, $post_id, $form ) {
$post = get_post( $post_id );
$mail["subject"] = $post->post_title . " - " . $mail["subject"];
return $mail;
}
The snippets from GitHub you should never update, as they will be replaced with plugins from WordPress.org repository which have the same name.
Thread Starter
lazyym
(@lazyym)
Perfect as usual. Woks great! Now, how can I modify that to contain a “Re:” in front of the post title in the subject and a link to the site in the message area? Ideally, a link to the post itself would be great! I hate to be a pain but this is fundamental stuff @gwin. Thank you sir!
Change the line
$mail["subject"] = $post->post_title . " - " . $mail["subject"];
to
$mail["subject"] = "Re: " . $post->post_title . " - " . $mail["subject"];
$mail["message"] .= "\r\n---\r\n";
$mail["message"] .= get_permalink( $post ) . "\r\n";
you will have “Re:” at beggining of the title and link to Advert at the bottom of the message.
Thread Starter
lazyym
(@lazyym)
Thanks Greg, so the complete function should be?
add_filter( "adverts_contact_form_email", "contact_form_email", 10, 3 );
function contact_form_email( $mail, $post_id, $form ) {
$post = get_post( $post_id );
$mail["subject"] = "Re: " . $post->post_title . " - " . $mail["subject"];
$mail["message"] .= "\r\n---\r\n";
$mail["message"] .= get_permalink( $post ) . "\r\n";
return $mail;
}
And it works! Thanks again!
Now I notice the site email displays as from. But when they click reply, it shows the senders email. Is there a way to display the from senders email in the from line rather than the admin email address?
I am already getting emails from those who’ve received messages in the admin inbox for my site.