Support » Plugin: Conditional Fields for Contact Form 7 » Incompability with “do_shortcode”

  • Resolved Cèsar Martí

    (@cesasrgalway)


    In my functions.php theme’s file, I have this code

    add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );
    
    function mycustom_wpcf7_form_elements( $form ) {
          $form = do_shortcode( $form );
          return $form;
    }

    I need it to use some shortcodes within “Contact Form 7” creator. I realised that “Contact Form 7 – Conditional Fields” is not working if I have that code. Anyone have an idea to fix it?

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jules Colle

    (@jules-colle)

    not sure what you mean exactly.. does this have anything to do with the conditional fields plugin?

    Thread Starter Cèsar Martí

    (@cesasrgalway)

    Yes. As I said, if you want to use shortcodes in Contact Form 7 you should have that function. But if you have it, Conditional Fields is not working.

    Plugin Author Jules Colle

    (@jules-colle)

    I’m not aware of this function, can you link me to the CF7 documentation page where you found this code?

    Thread Starter Cèsar Martí

    (@cesasrgalway)

    Hi Jules.

    I think there’s not any official documentation, it’s just a trick that uses a lot of people in order to use shortcodes in CF7.

    By default, shortcodes are not allowed in CF7. As example, if you want to use design shortcodes you have to use that code I said in functions.php of your theme folder. Another easier example… image you have a [br] shortcode that when you use it prints the <br> tag (it doesn’t have any sense, but it’s an easy example). If you write [br] in CF7, you just will have that as a text instead of <br> (a line break). That’s the reason to use that code with the do_shortcode function.

    I guess the incompatibility with “Contact Form 7 – Conditional Fields” is because you use the functions “wpcf7_add_form_tag” or “wpcf7_add_shortcode” in “cf7cf.php”, but it’s just an idea.

    I hope you can fix it.

    Regards and thanks for the feedback.

    Plugin Author Jules Colle

    (@jules-colle)

    Hi I just tested this and it works. Make sure the shortcode exists.

    Adding only this line to your functions.php file should suffice:

    add_filter( 'wpcf7_form_elements', 'do_shortcode' );

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Incompability with “do_shortcode”’ is closed to new replies.