Tanvir Tanvir - 1 year ago 127
PHP Question

Contact form 7 email subject should be post title

I am using custom form 7

I want that, If anyone clicks the mail button under single post in wordpress, it will automatically redirect him to contact-us page and then subject of the mail will be the post title.

How can I do that?

Answer Source

Solved with this code:

if( $_SERVER['HTTP_REFERER'] !== '' ) {
    $referer = $_SERVER['HTTP_REFERER'];
    $id = url_to_postid($referer);
    $subject = get_the_title($id);
} else {
    $subject = '';

input field:<input id="post-referer" value="<?php echo esc_attr($subject); ?>" type="hidden">

then used jQuery to fill up the subject field from 'post-referer' field's value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download