-
AuthorPosts
-
July 19, 2018 at 8:49 pm #987621
Dear members and dear support,
how i get in the contact form subject auotmatic the post title?
Every post have a contact form below. And when a customer write me, than should automatic the post title as the subject.
Its this please possible? I think i must create a function in the function.php. But i dont know how…Thanks for your help.
regards stp
July 20, 2018 at 9:37 pm #988041Hey strumpumpel,
You can use this code – just add it to the child theme functions.php file:
add_filter('avf_form_subject','avia_change_mail_subject', 10, 3); function avia_change_mail_subject($subject, $new_post, $form_params) { if( is_single() ) { $subject = urldecode(get_the_title()); } return $subject; }
If you want to add some static text before the post title use this code:
add_filter('avf_form_subject','avia_change_mail_subject', 10, 3); function avia_change_mail_subject($subject, $new_post, $form_params) { if( is_single() ) { $subject = 'A new message on:' . urldecode(get_the_title()); } return $subject; }
and replace “A new message on:” with some custom text.
Best regards,
DudeJuly 21, 2018 at 3:03 pm #988162Dear dude,
great thanks for you answer! I edit this code in the function.php from my child theme. But not happend in my subject on this contact formular…
what for a typ must the subject field?
Formular type element:
text input or selection field or text area or checkbox or date picker or own html?
I think date picker, checkbox and own html is not right.
I try them out the other elements, but dont happend when i open the post with contact fomular. The subject is empty….
What’s wrong?Thanks, thanks for your help!
July 24, 2018 at 1:47 pm #989185Hi,
Thanks for the update.
I adjusted the filter a bit. Please try it again.
add_filter('avf_form_subject','avia_change_mail_subject', 10, 3); function avia_change_mail_subject($subject, $new_post, $form_params) { if( is_single() ) { $subject = 'A new message on:' . urldecode(get_the_title(get_the_ID())); } return $subject; }
Best regards,
IsmaelJuly 24, 2018 at 4:43 pm #989249Guys??? You are the biggest! :)
The code worked perfectly now! Big thank you! :)Question: What is the 10 and 3 in “add_filter(‘avf_form_subject’,’avia_change_mail_subject’, 10, 3);”
Biggest thanks and by by :)
July 24, 2018 at 7:57 pm #989328Hi,
Hahaha that is more advanced coding nuances. Priority is 10, accepted arguments is 3.
Best regards,
Jordan Shannon -
AuthorPosts
- You must be logged in to reply to this topic.