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'm using a Contact Form 7 filter to take action after the email is sent. How can I limit this action to only one form? There are multiple forms on different pages, and I don't want this action to run after every form, only one specific form.

I tried limiting the action to the page where the form is using an if clause, but then the "action" doesn't complete. Once I remove the if clause, then the action works.

function foo() {

   if(is_page('bar') {

     // some action
add_action( 'wpcf7_mail_sent', 'foo', 1 );
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You know the id of the form from the shortcode, you can do stuff just for that particular form. Here's some sample code for that, just replace $myform_id with your form id:

add_action( 'wpcf7_mail_sent', 'wp190913_wpcf7' );

 * Do stuff for my contact form form. This function shouldn't return aything
 * @param WPCF7_ContactForm $contact_form wpcf7 object, passed by refference
function wp190913_wpcf7( $contact_form ) {

    // Not my desired form? bail
    if ( $contact_form->id !== $myform_id )

    // Do stuff for my contact form
share|improve this answer
Thanks. Accepted and upvoted. –  chowwy Sep 19 '13 at 22:16
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.