Shortcode to protect Emails from spam bots?

PHP Code Snippets/Functions
/*
* To prevent spam bots, email addresses are converted from characters to HTML entities.
* How to use: [email youremail="youremail@email.com"]
*/
add_shortcode( 'email', function( $atts , $content = null ) {
	$email = $atts['youremail'];
	$fontsize = (!empty($atts['fontsize']) ? $atts['fontsize'] : '18');
	return '<a style="font-size: '.$fontsize.'px;" href="' . esc_url('mailto:' . antispambot( $email ) ) . '">' . esc_html( antispambot( $email ) ) . '</a>';
});

Leave a Reply

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