Protect your email address on a WordPress site
WordPress comes with some useful built in functions for sanitising and protecting content which are often underused. For example, ever needed to protect an email address on a site footer or contact template so it cannot be picked up by spammers? Enter ‘antispambot’!
Antispambot’s default usage is as follows where the email you want to hide is wrapped in the antispambot function. This will show the email address when displayed in a browser but will show a series of HTML entities such as “com” when viewing the HTML.
<?php echo antispambot( '[email protected]' ); ?>
If you wanted to take this a step further and include in a mailto link then you could use the following code:
<a href="mailto:<?php echo antispambot( '[email protected]' );?>"><?php echo antispambot( '[email protected]' );?></a>
Whilst its not a fool proof solution it will allow some protection for your on-site email addresses. Its something we use on every site we produce and you can read more about ‘antispambot’ at the WordPress Codex Antispambot.