WordPress antispambot?
-
Hello, I like to publish my email address on my website but want to protect it from spammers. I have read about the build in function called antispambot. I like to use that instead of a plugin.
https://codex.www.ads-software.com/Function_Reference/antispambot
I don’t know exactly how to set this up. Maybe like this:
1 – add this code to my function.php file:
/** * 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; } $content = antispambot( $content ); $email_link = sprintf( 'mailto:%s', $content ); return sprintf( '<a href="%s">%s</a>', esc_url( $email_link, array( 'mailto' ) ), esc_html( $content ) ); } add_shortcode( 'email', 'wpcodex_hide_email_shortcode' );
2 – Change the email links on my contact page into a sort code[email][email protected][/email]
Is that all?
Thank you very much for your help!
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘WordPress antispambot?’ is closed to new replies.