Tanvir Tanvir - 1 month ago 20
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

Solved with this code:

<?php
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.

Comments