Title: Custom shortcode in emails
Last modified: August 21, 2016

---

# Custom shortcode in emails

 *  Resolved [MikepFive](https://wordpress.org/support/users/mikepfive/)
 * (@mikepfive)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/)
 * Hi,
 * I’ve used Contact From 7 in several sites – and think its excellent.
 * I’ve got a particular requirement to add a ‘custom’ short code to the email (
   actually to uses IP address to track country – but that’s only my particular 
   use)
 * I’ve used the following to facilitate custom shortcodes in forms:
 * add_filter( ‘wpcf7_form_elements’, ‘mycustom_wpcf7_form_elements’ );
 * function mycustom_wpcf7_form_elements( $form ) {
    $form = do_shortcode( $form);
 * return $form;
    }
 * but can’t find a way to do the same thing in the email template (and have resorted
   to editing ‘special-mail-tags.php’ to achieve what I need to do – but that’s 
   not very elegant or easy to maintain)
 * Is there a better way to use custom shortcodes in email output from Contact Form
   7 ?
 * regards,
 *  Mike
 * [http://wordpress.org/extend/plugins/contact-form-7/](http://wordpress.org/extend/plugins/contact-form-7/)

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

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/#post-3931618)
 * [Special Mail Tags](http://contactform7.com/special-mail-tags/)
 * You can get IP address by using `[_remote_ip]` in mail content.
 *  Thread Starter [MikepFive](https://wordpress.org/support/users/mikepfive/)
 * (@mikepfive)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/#post-3931628)
 * Takayuki,
 * thanks for getting back to me so promptly.
 * I know that I can get IP address by using [_remote_ip] in mail content – I actually
   use it – but I also want to lookup the Country that the address relates to, so
   I use the Quick Flag plugin, which also gives me a nice graphic image of the 
   National Flag!
 * For the moment I’ve simply added:
 *  elseif ( ‘quick-flag’ == $name )
    $output = do_shortcode(‘[quick-flag]’);
 * to the end of the function wpcf7_special_mail_tag_for_post_data() in the special-
   mail-tags.php file to achieve what I want – but would prefer a better solution
   that won’t break when I update Contact Form 7.
 * Thanks for your help with this – and for a **great** plugin.
 * Mike
 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/#post-3931725)
 * Try this:
 *     ```
       add_filter( 'wpcf7_special_mail_tags', 'your_special_mail_tag', 10, 3 );
   
       function your_special_mail_tag( $output, $name, $html ) {
       	if ( 'quick-flag' == $name )
       		$output = do_shortcode( '[quick-flag]' );
   
       	return $output;
       }
       ```
   
 * Place `[quick-flag]` where you wish the flag.
 *  Thread Starter [MikepFive](https://wordpress.org/support/users/mikepfive/)
 * (@mikepfive)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/#post-3931735)
 * Takayuki,
 * brilliant !!
 * Works a treat.
 * I’m very grateful for A) a GREAT plugin B) an EXCELLENT solution C) the SPEED
   and QUALITY of your support
 * I’m in your debt
 * Many thanks
 * Mike
 *  [ikawares](https://wordpress.org/support/users/ikawares/)
 * (@ikawares)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/#post-3931893)
 * good day ,
    thank you for the solution u mentioned in this post . i’ve tried 
   it but seems sth goes wrong in my recipient email .
 * User IP :60.53.86.128
 * IP Location : Malaysia (<img class=”quick-flag” title=”Malaysia” src=”[http://www.nicollo.com/wp-content/plugins/quick-flag/img/flags/MY.gif&#8221](http://www.nicollo.com/wp-content/plugins/quick-flag/img/flags/MY.gif&#8221);/
   >)
 * any idea why the flag cant be shown in email
 * Thank You
 *  [Tim Berneman](https://wordpress.org/support/users/tberneman/)
 * (@tberneman)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/#post-3931894)
 * I want to do something very similar but I want to pass my shortcode one of the
   cf7 variables. How do I get those in my function?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/#post-3931895)
 * **[@ikawares](https://wordpress.org/support/users/ikawares/)** & **[@tim](https://wordpress.org/support/users/tim/)
   Berneman**: If you require assistance then, as per the [Forum Welcome](http://codex.wordpress.org/Forum_Welcome#Where_To_Post),
   please post your own topic.

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

The topic ‘Custom shortcode in emails’ 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/)

 * 7 replies
 * 5 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/custom-shortcode-in-emails/#post-3931895)
 * Status: resolved