Title: custom shordcode in message
Last modified: August 30, 2016

---

# custom shordcode in message

 *  Resolved [maestro2012](https://wordpress.org/support/users/maestro2012/)
 * (@maestro2012)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-shordcode-in-message/)
 * How add custom shortcode to message?
 * I use Advanced Custom Fields, and must send some data from custom fields in contact
   form 7 message.
 * [https://wordpress.org/plugins/contact-form-7/](https://wordpress.org/plugins/contact-form-7/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [davmerit](https://wordpress.org/support/users/davmerit/)
 * (@davmerit)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-shordcode-in-message/#post-6681079)
 * add a `name` attribute on the form element and make your mail section shortcode
   out of it.
 * Example:​​
 * `<li name="custom_name"> some list </li>`
 * in the mail section/message you will use `[custom_name]` as your shortcode​​​
   to display input from the
 * `<li> field in your email.</li>`
 *  Thread Starter [maestro2012](https://wordpress.org/support/users/maestro2012/)
 * (@maestro2012)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-shordcode-in-message/#post-6681161)
 * I mean, to shortcode, like this:
 *     ```
       // [foobar]
       foobar_func function ($ atts) {
       return "foo and bar";
       }
       add_shortcode ('foobar', 'foobar_func');
       ```
   
 * So that was attached to the message content “foo and bar”.
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-shordcode-in-message/#post-6681162)
 * Try this: [Custom shortcode in emails](https://wordpress.org/support/topic/custom-shortcode-in-emails?replies=8#post-4422110).
 * [@mods](https://wordpress.org/support/users/mods/): A not closed `<li>` close
   to the end of above post of _davmerit_ seems to kill the layout..
 *  [Tim Nash](https://wordpress.org/support/users/tnash/)
 * (@tnash)
 * Spam hunter
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-shordcode-in-message/#post-6681163)
 * Layout Fixed 🙂 Folks remember to always encapsulate your code with backticks
   or use the code button.
 * Thanks
 *  Thread Starter [maestro2012](https://wordpress.org/support/users/maestro2012/)
 * (@maestro2012)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-shordcode-in-message/#post-6681167)
 * Ov3rfly, thank you for link, this is working.
 *     ```
       add_filter( 'wpcf7_special_mail_tags', 'foobar_func', 10, 3 );
       //[foobar]
       function foobar_func( $atts ){
       	return "foo and bar";
       }
       add_shortcode( 'foobar', 'foobar_func' );
       ```
   
 * insert [foobar] to Message Body.
 *  [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * (@ov3rfly)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/custom-shordcode-in-message/#post-6681169)
 * This might work for this one case but it is just wrong, it does return the same
   output for every possible special mail tag.
 * Here is a correct version based on the linked code example:
 *     ```
       add_filter( 'wpcf7_special_mail_tags', 'your_special_mail_tag', 10, 3 );
   
       function your_special_mail_tag( $output, $name, $html ) {
       	if ( 'foobar' == $name )
       		$output = do_shortcode( '[foobar]' );
   
       	return $output;
       }
   
       // [foobar]
       function foobar_func( $atts) {
       	return "foo and bar";
       }
       add_shortcode ('foobar', 'foobar_func');
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘custom shordcode in message’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 6 replies
 * 4 participants
 * Last reply from: [Ov3rfly](https://wordpress.org/support/users/ov3rfly/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/custom-shordcode-in-message/#post-6681169)
 * Status: resolved