I noticed that any shortcode that is not part of the contact form 7 builtin shortcodes dont work.

For example: I am trying to use an accordion shortcode between form elements in contact form 7. But the code dont work.

How to solve this without editing contact form 7 core files?

  • Not sure that you can do this. Shortcodes have to be in a page or post, don't they. I don't think you can put a shortcode between form elements. Where would you put them? ... in the contact form 7 settings? You cant do that there AFAIK ( unless you're following some contact form 7 instructions I haven't heard of). Commented Mar 12, 2012 at 12:59

1 Answer 1


There's two ways to do what you're wanting. First way is to add this code to functions.php of the Contact Form 7 plugin:

add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );

function mycustom_wpcf7_form_elements( $form ) {
$form = do_shortcode( $form );

return $form;

That allows you to drop shortcodes directly into CF7. Second is to add the Accordion in manually with HTML in the contact form, like this:

<!-- begin class .wp-accordion -->
<div class="wp-accordion wpui-light">

    <!-- First tab's panel -->
    <h3 class="wp-tab-title">Tab 1</h3>
    <!-- First tab's contents -->
    <div class="wp-tab-content">
          All the contents of first tab goes here....
    </div><!-- end first tab -->

      <!-- Like so, Second panel -->
      <h3 class="wp-tab-title">Tab 2</h3>
      <div class="wp-tab-content">
            Contents of the second tab

</div><!-- end class wp-accordion -->

I think the second method is preferable, since there is no modifying of core plugin files. I hope this helps out!

  • 4
    Actually - you can add the filter code in your theme's functions.php and shortcodes will work properly inside a CF7 form. I can't confirm whether the specific one(for the accordion) will work or not though - I've only tested with a shortcode that doesn't contain any CF7 shortcodes, but basically it all depends on how the shortcode in question is handled. Commented Mar 20, 2013 at 12:35
  • 15
    indeed, a simple add_filter( 'wpcf7_form_elements', 'do_shortcode' ); does the trick from my child theme's functions.php. Commented Sep 30, 2013 at 3:21
  • 1
    If you want to use the same content in more than one location on your site, you're better off creating a shortcode (localizable if necessary), than to cut and paste the same HTML all over the place. Commented Sep 12, 2014 at 0:02
  • I have used this code but it is not working, so can you please help? wordpress.stackexchange.com/questions/359534/… Commented Feb 26, 2020 at 14:58

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