Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to execute a shortcode after the user will press the submit button. I am using Contact form 7 and have inserted the form by a shortcode in the Post edit section.

It's basically a form collecting data and after submit, I will redirect the user to PayPal in a new window. The shortcode for the PayPal button works already on it's own.

I have tried this function but the form seems to get stuck, I get the loading icon forever, the message is delivered but most important, it's not executing my shortcode. Not even a simple echo "test";.

add_action ('wpcf7_mail_sent', 'after_mail_sent');
function after_mail_sent () {
  echo do_shortcode ('[book]');

Any ideas please?

share|improve this question
Conform that shortcodes is working or not. –  ayyan Mar 6 '12 at 13:10
The shortcode is working by itself, if I do [book] in page edit, it does show up on my page. I just don't know how to edit the functions file of that CF7 to load my shortcode. Update => I do get the email even if I am not shown the "success" message, by using that function, but what's in the function doesn't show up. –  Chris Demetriad Mar 6 '12 at 13:19
I've also realised that I will have to hide the submit button before showing the button from my shortcode.. grr, this is getting worse :/. –  Chris Demetriad Mar 6 '12 at 13:23
The code for the [book] shortcode would help. –  s_ha_dum Jun 13 '13 at 15:43
that wouldn't have been of any help, I've already mentioned the shortcode is working fine; it's content is irrelevant given the question –  Chris Demetriad Jun 15 '13 at 20:28
add comment

1 Answer

You could customize Contact Form 7 so that once the button is pressed, it leads to a page where you have your shortcode. You basically are making the a page that should be a confirmation just have your shortcode.

This thread has the info on the redirect: http://wordpress.org/support/topic/plugin-contact-form-7-redirect-to-thank-you-page-on-submit?replies=23

share|improve this answer
Link only answers are discouraged. If something happens to that link the answer becomes useless. Please try to make your answer here stand alone. –  s_ha_dum Jun 13 '13 at 14:51
Thanks for the heads up. –  Shaan Singh Jun 13 '13 at 15:35
"I need to execute a shortcode after the user will press the submit button.". This is what I needed. –  Chris Demetriad Jun 15 '13 at 20:30
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.