-3

How can I use Contact Form 7 form tags or shortcodes in WordPress Posts and Pages. Any ideas would be appreciated.

Thanks in advance!

1 Answers1

0

I believe you're looking for "how to add new fields and on submit button in contact form 7. " The syntax for the form is like something below. enter image description here

Here's a demo working code for you.

<div class="row clearfix">
  <div class="form-group col-md-4 col-sm-6 col-xs-12">
     <div class="form-group-inner">
        <div class="icon-box">
           <label for="your-name">
             <span class="icon flaticon-user168"></span>
           </label>
        </div>
        <div class="field-outer">
          [text* your-name name:username id:your-name placeholder "Your Name"]
        </div>
    </div>
  </div>
  <div class="form-group col-md-4 col-sm-6 col-xs-12">
     <div class="form-group-inner"><div class="icon-box">
      <label for="your-email">
       <span class="icon flaticon-new100"></span>
      </label>
     </div>
     <div class="field-outer">
      [email* name:email id:your-email placeholder "Email"]
     </div>
  </div>
 </div>
 <div class="form-group col-md-4 col-sm-12 col-xs-12">
   <div class="form-group-inner">
     <div class="icon-box">
       <label for="your-subject">
         <span class="icon flaticon-edition2"></span>
       </label>
     </div>
     <div class="field-outer">
       [text* name:subject id:your-subject placeholder "Subject"]
     </div>
    </div>
   </div>
   <div class="form-group col-md-12 col-sm-12 col-xs-12">
    <div class="form-group-inner">
      [textarea name:message placeholder "Your Message"]
    </div>
   </div>
   <div class="form-group col-md-12 col-sm-12 col-xs-12 text-right">
    [submit class:input-submit class:hvr-bounce-to-right name:submit-form "Send Message"]</div>
  </div>

Paste the above code into your new contact form and it should create a new form with name, subject, email and message fields. You can call this form by using shortcode either in page or in your ".php" file. I used this in a php file like below:

<?php echo do_shortcode( "[contact-form-7 id='184' title='Contact form 1']", $ignore_html = false ); ?>

You can also post the shortcode from the contact form 7 into the page directly. Here is a small tutorial for you.

Hassaan Ali
  • 1,038
  • 7
  • 16
  • Hey there @hassaan-ali Thanks for your answer but I want to display the contact form 7 form tags shortcode in WordPress Posts and Pages. E.g.: `[text* your-name name:username id:your-name placeholder "Your Name"]` So I need to only output the `[your-name]` in WordPress specific post. I know CF7 form tags is not intended to work on WordPress Posts but I think there might be any solution regarding this. – Yash Baldawa Nov 01 '18 at 05:02
  • Thanks yash for getting back to me. You can find your response here: https://stackoverflow.com/a/13192822/7698734 Edit: The author created a custom function for a field you have to create custom functions for the shortcode to be enabled. – Hassaan Ali Nov 01 '18 at 07:31
  • Hey there hassan, `wpcf7_add_shortcode` is actually deprecated. Have a look: http://hookr.io/functions/wpcf7_add_shortcode/ – Yash Baldawa Nov 02 '18 at 09:31