Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/antispambot


Converts selected email addresses characters to HTML entities to block spam bots. Not all characters in the email address are converted: the selection is random and changes each time the function is called.


<?php antispambot$email_address$hex_encoding ?>


(string) (required) Email address.
Default: None
(integer) (optional) 0 or 1. Use 0 to only allow decimal encoding (&#123;) and 1 to also allow hex encoding (&x7B;).
Default: 0

Return Values

Converted email address.


 * Hide email from Spam Bots using a shortcode.
 * @param array  $atts    Shortcode attributes. Not used.
 * @param string $content The shortcode content. Should be an email address.
 * @return string The obfuscated email address. 
function wpcodex_hide_email_shortcode( $atts , $content = null ) {
	if ( ! is_email( $content ) ) {

	return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );

To use this in your WordPress Content area all you have to do it wrap it in a short code.


You can also use this in a plain text widget if you add this filter to your function file as well.

add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );

Default Usage

echo antispambot( 'john.doe@mysite.com' );

This will output the email like this in the HTML:


But it will appear as a normal email address to anyone using a web browser:



Change Log

Since: 0.71

Source File

antispambot() is located in wp-includes/formatting.php.


See also index of Function Reference and index of Template Tags.