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.

Read More

How can I do that?

Related posts

3 comments

  1. Haven’t used it before, but this plugin claims to work for your purposes: https://wordpress.org/plugins/contact-form-7-dynamic-text-extension/

    You will then create your mail link to contain the post title via a query parameter with (maybe with http_build_str()), so that your URL becomes like:

    http://example.com/contact-us/?title=my+post+title
    

    After which you have to create the new CF7 tag as such, to auto-populate with the $_GET variable.

    [dynamictext post_subject "CF7_GET key='title'"]
    
  2. 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 are closed.