Problems sending post tile with Contact Form 7 email

[ad_1]

Hello fello WordPressers,

I’m in a scenario where I need to send the post tile in mails sent from a CF7 form. Normally, you would use the \[\_post\_title\] tag to do this, but here, that tag returns empty, probably because

* the form is not inside the post content
* the post is a custom post type

I’ve found an official script to add custom shortcodes to mail sent by CF7.

I’ve set up the shortcode like this:

add_shortcode(“post_title”, “get_the_title”);

This is tested and works anywhere on the page.

Then, this is the script to add custom tags in CF7 emails:

function my_special_mail_tag($output, $name, $html)
{
if (“post_title” == $name) {
$output = do_shortcode(“[$name]”);
$output .= “: the shortcode was found.”;
}

return $output;
}
add_filter(“wpcf7_special_mail_tags”, “my_special_mail_tag”, 10, 3);

Also tested, however,

$output = do_shortcode(“[$name]”);

always returns empty. I’m only getting the test output: “: the shortcode was found.”

Any help in getting the post title in those mails would be greatly appreciated 🙂

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer