Encode Email Address With Shortcode


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="http://wpcodesnippet.com/encode-email-address-shortcode/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

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads