Skip to content

Instantly share code, notes, and snippets.

@robertdall
Last active October 13, 2015 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robertdall/4230428 to your computer and use it in GitHub Desktop.
Save robertdall/4230428 to your computer and use it in GitHub Desktop.
Email Short Code
// Hide Email from Spam Bots using antispam bot http://codex.wordpress.org/Function_Reference/antispambot
function HideMail($atts , $content = null ){
if ( ! is_email ($content) )
return;
return '<a href="mailto:'.antispambot($content).'">'.antispambot($content).'</a>';
}
add_shortcode( 'email','HideMail');
@robertdall
Copy link
Author

All the above short code to your function file.

Now all you have to do is wrap the email address in [email]robert@example.com[/email] for it work.

This short code updated Oct/2013 now uses the WordPress antispambot function reference. http://codex.wordpress.org/index.php?title=antispambot

@jkudish
Copy link

jkudish commented Dec 7, 2012

I have forked your shortcode here: https://gist.github.com/4235056 and made some important improvements to it:

  • using WordPress coding standards
  • removing the image in the link, that seemed very specific to the Robert's use case and not general use
  • adding validation that the passed string in $content is an email address, and if not, just return out of the function, avoiding potential issues if it wasn't an email address
  • added proper output escaping to the link, for security reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment