Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //  Coding directly into a page template, you can use the built-in WordPress function below:
  2. antispambot( "youremail@yoursite.com" );
  3.  
  4. //  A way to make use of the antispambot() function within posts and pages content using a shortcode
  5. //  EMAIL ENCODE SHORTCODE
  6. function encode_email_shortcode( $atts, $address = null ){
  7.     if( !is_email( $address ) ){
  8.         return;
  9.     }
  10.     $mailtoaddr = antispambot( $address );
  11.     $maillink   = '<a href="mailto:';
  12.     $maillink   .= $mailtoaddr;
  13.     $maillink   .= ( isset( $atts['subject'] ) ? '?subject='.$atts['subject'] : '' );
  14.     $maillink   .= '" target="_blank">';
  15.     $maillink   .= ( isset( $atts['output'] ) ? $atts['output'] : $mailtoaddr );
  16.     $maillink   .= '</a>';
  17.     return $maillink;
  18. }
  19. add_shortcode( 'email', 'encode_email_shortcode' );
  20.  
  21. /*
  22.     Code snippet above goes in your theme function.php
  23.     Use the following structure to safely display an email address in your post or page content:
  24.  
  25.     [email]you@you.com[/email]
  26.     [email subject="Website Inquiry"]you@you.com[/email]
  27.     [email output="Click here to contact us"]you@you.com[/email]
  28.     [email output="Click here to contact us" subject="Website Inquiry"]you@you.com[/email]
  29.  
  30.  */