antispambot() wordpress function and usage This text is not used because the data attribute has a value

antispambot() wordpress function and usage

Home / WordPress / WordPress Wiki / antispambot() wordpress function and usage

antispambot( string $email_address, int $hex_encoding )
Converts email addresses characters to HTML entities to block spam bots.



(string) (Required) Email address.


(int) (Optional) Set to 1 to enable hex encoding.


(string) Converted email address.

Sample Usage


 * 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 wpdocs_hide_email_shortcode( $atts , $content = null ) {
    if ( ! is_email( $content ) ) {
    return '<a href="' . esc_url('mailto:' . antispambot( $content ) ) . '">' . esc_html( antispambot( $content ) ) . '</a>';
add_shortcode( 'email', 'wpdocs_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' );

Edited with a contribution from @johnrafferty

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments