WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[resolved] Include Custom Shortcodes in Form? (7 posts)

  1. Ryan Cowles
    Member
    Posted 2 years ago #

    I have been using Contact Form 7 for some time, but I recently had a problem come up that I couldn't seem to figure out.

    When generating a form with CF7, I want to include a custom shortcode that I use throughout the rest of my blog. All the shortcode does is insert a styled div. However, when I enter it in the Form editor, it just shows up as [custom-shortcode] on the front end. I am assuming there may need to be a do_shortcode() somewhere inside the CF7 files, but I can't seem to figure out where.

    Any ideas? I just want to be able to accomplish something like the following:

    <p>Your Name (required)<br />
        [text* your-name] </p>
    
    [custom-shortcode]
    
    <p>Your Email (required)<br />
        [email* your-email] </p>

    Where [custom-shortcode] results in something like <div class="custom-div"></div>.

    Thanks for reading! Any feedback or ideas are appreciated.

    http://wordpress.org/extend/plugins/contact-form-7/

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 2 years ago #

    Try adding this into the functions.php file in your theme:

    add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );
    
    function mycustom_wpcf7_form_elements( $form ) {
    	$form = do_shortcode( $form );
    
    	return $form;
    }
  3. davejuk
    Member
    Posted 2 years ago #

    I had this problem too - thanks for the solution Takayuki Miyoshi, works great.

  4. Ryan Cowles
    Member
    Posted 2 years ago #

    Thank you so much Takauki!

  5. praisehim
    Member
    Posted 2 years ago #

    Hi!

    This worked for me as well. I am using the theme Karma with WordPress 3.3.1

    Thanks once again Takauki!

  6. Geraldo Augusto
    Member
    Posted 2 years ago #

    This tip worked for me, but the output of shortcode was written outside Contact Form 7 tag <form>.

    Any feedback or ideas are appreciated.

  7. Charlie
    Member
    Posted 1 year ago #

    THANK YOU Takayuki Miyoshi

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic