Shortcode in email body
-
Great plugin! only issue that bothers me: shortcode (other than the one from wpcf7) is not working in the email body?
has anybody any hint who to make this work?
@tz-media being a code wizard, can you help? this would be appreciated very much. we have an online test and would like to include the score in the wpcf7-form you have to fill out once you made the test (so we know from the form how many points you made and can react accordingly,
best, K
-
This topic was modified 6 years, 10 months ago by
W★.
The page I need help with: [log in to see the link]
-
This topic was modified 6 years, 10 months ago by
-
Hello filmpuls,
that’s right, currently the plugin only supports shortcodes inside the form itself, not inside mails.
I’ve looked into it and there seems to be no trivial way to simply activate all shortcodes, as there is for the form itself. At least for shortcodes that are not self contained (meaning it has attributes or content between opening and closing tags), I need to do build a configuration interface in the backend to alias them to a simple self-contained shortcode. Which I’m definitively planning to build.
That being said, perhaps https://www.howtosnippets.net/wordpress/make-custom-shortcodes-work-in-contact-form-7-mail-form-templates/ (section “Enable shortcodes inside the Mail Template”) might help you in the meantime. If you need help with this, please just reply to this with the shortcode you want to include, and I reply with the code snippet you need.
Best, Tobias
Hi Tobias aka @tz-media,
thx for taking care of my problem. I’ve found that code but it looks like I did not understand it well enough.
what I want to do: I have a survey on a page that outputs the result of a quiz as a short code in form of
[survey_answers id="464958745" data="score" style="plain" uid="true" session="last"]
on the same page is a wpc7 form that people can send and what I want to do is include the score in the email so I can act accordingly to the score.
I found the original code
function my_special_mail_tag( $output, $name, $html ) { if ( 'myshortcode' == $name ) $output = do_shortcode( "[$name]" ); return $output; } add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );
but did not know how to put in my shortcode.
So please let me know what I misunderstood and you make my day 😉regards, K
Hi @filmpuls,
actually it’s the other way around:
function my_special_mail_tag( $output, $name, $html ) { if ( 'score' == $name ) $output = do_shortcode( "[$name]" ); return $output; } add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );
Hope this solves your problem 😉
PS: I see you edited your post. Assuming
[code]
without any additional parameters prints the score, this should work.-
This reply was modified 6 years, 10 months ago by
Tobias Zimpel. Reason: Reacted to edit of parent post
Hi @tz-media
I probably risk to sound stupid, but: what is the other way round? put that code 1:1 in functions.php?
Hi @filmpuls,
In your unedited post, you wrote how you have edited the example code. That’s what my “the other way around” was referring to.
So if you put the code provided by me into functions.php it should work. If not, please don’t hesitate to write again, and I’ll try to help.
@tz-media not working, but I assume that this is because the shortcode I must include is
[survey_answers id="464958745" data="score" style="plain" uid="true" session="last"]
and not just [code]?
@tz-media ps: tried to wrap my longer shortcode also into a single word code like [code] using the plugin post snippets, and then added [code] to the email, but no difference (probably because code in code is a bad idea) ...
Is this – including the id – the exact same code for everyone? Or is the id dynamic? If so, is there any way to “know” the id?
@tz-media it is always this code for everyone (this id is identifying the quiz), so it is not dynamic.
Hi @filmpuls,
then this might do the trick:
function my_special_mail_tag( $output, $name, $html ) { if ( 'score' == $name ) $output = do_shortcode( '[survey_answers id="464958745" data="score" style="plain" uid="true" session="last"]' ); return $output; } add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );
And the shortcode you have to use in your email template is
[score]
.PS: Thanks for the great review.
-
This reply was modified 6 years, 10 months ago by
Tobias Zimpel.
Hi @tz-media
“It’s wingardium leviOsa, not leviosAH.”
– Harry Potter and the Philosopher’s StoneThat does the magic! THANK YOU!
Hi @filmpuls,
glad I could help where Hermione couldn’t… 😉 ^^
I’ve created a new entry.
-
This reply was modified 6 years, 9 months ago by
gaucho code.
-
This reply was modified 6 years, 9 months ago by
gaucho code.
-
This reply was modified 6 years, 10 months ago by