Encode Email Address With Shortcode

How to Encode Email Address With Shortcode

in Security
Google+ LinkedIn

It is generally a bad idea to post your email address in plain text format on your website. It will most likely to get picked up by a spam bot and once it is in the hands of a spammer, your inbox will be filled with spam in no time.

WordPress offers a way to protect your email address from displaying it publicly in plain text format. Here is a shortcode to encode email address in WordPress.

// encoded your email address with shortcode
function wcs_encode_email_address( $atts, $content ) {
    return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
add_shortcode( 'email', 'wcs_encode_email_address' );

Now you can use “email” shortcode in your content to display encoded email address. Here is a example.

// email shortcode usage

Share the love

If you like this snippet, share it with others!

Leave a Reply

Your email address will not be published. Required fields are marked *