• My form is embedded in a template file single-couses.php using do_shortcode. This is the single template of a custom post type “courses”. I am trying to display the title of a CPT single page within the form, and also in the email that is sent by the form. Here is my code:

    add_action( 'wpcf7_init', 'custom_add_form_tag_cpttitle' );
     
    function custom_add_form_tag_cpttitle() {
        wpcf7_add_form_tag( 'cpttitle', 'custom_cpttitle_form_tag_handler', array( 'name-attr' => true ) ); // "cpttitle" is the type of the form-tag
    }
     
    function custom_cpttitle_form_tag_handler( $tag ) {
        return the_title('<h3>','</h3>');
    }

    The title shows up within the form using the shortcode [cpttitle].

    When I add [cpttitle] to the mail tab of the form, it does nothing and displays the shortcode as text (“[cpttitle]”) in the resulting email message.

    How can I add [cpttitle] to the email so it shows in the email message?

    I have found this code:

    // define the wpcf7_posted_data callback 
    function my_wpcf7_posted_data( $array ) { 
        // make action magic happen here... 
    }; 
             
    // add the action 
    add_action( 'wpcf7_posted_data', 'my_wpcf7_posted_data', 10, 1 );

    How do I use this code to add my [cpttitle] to the email?

  • The topic ‘Add custom post type title to the email’ is closed to new replies.