I want to send an email with contactform 7 dynamic hidden field wordpress plugin, to get dynamic content to the email.
This is possible while using a shortcode. So I wrote the shortcode and the function, and it seems like it could work, because on the website, the correct output is displayed, but it doesn’t send it with the mail. I need to get content from several posts and custom fields by ID displayed as list.
It sends the proper content when there is a simple return 'random text';
But it doesn’t send anything with echo
for example.
So how can I get the content created by the function in a way, that it is a simple return
, that can be sent?
function show_list_function() {
if(!empty($_SESSION['acts'])){
foreach($_SESSION['acts'] as $actID){ //this gives the right content, but doesn't send with the mail
echo get_the_title($actID);
the_field('lange', $actID);
}
} else {
return 'Nothing selected'; //this is working
}
}
add_shortcode( 'show_list', 'show_list_function' );
Thanks for any help and tips!
2
Answers
Shortcode output can’t be echo’d out, it must be returned, since
do_shortcode
is used byecho do_shortcode()
From the codex:
You can use ob_start() and ob_get_clen();