This GitHub repository contains PHP code which obfuscates all email addresses present in your WordPress site's content and theme files. It employs output buffering and regex pattern matching to replace all instances of mailto
links with their obfuscated versions, thereby providing an effective measure against email harvesting spam bots.
The code initiates an output buffer before the page starts rendering, using a callback function that will modify the buffer's contents. At the end of page rendering, it applies the callback function to the buffer's contents, effectively obfuscating all mailto
email addresses found in the buffer.
The email obfuscation is achieved using WordPress's antispambot
function, which is a popular mechanism for deterring spam bots from harvesting email addresses.
To use this code in your WordPress theme:
- Copy and paste the code into your theme's
functions.php
file or a suitable custom plugin file. - The code will automatically hook into the
get_header
andwp_footer
actions, ensuring that the entire content of your website is passed through the obfuscation process.
- Uses WordPress's built-in
antispambot
function for email obfuscation. - Utilizes PHP output buffering and callback mechanism to process entire page content.
- Hooks into WordPress actions for seamless integration with theme files.
- Adds an effective layer of protection against email harvesting spam bots.
- Prevents email harvesting, reducing spam, enhancing user trust, and potentially improving SEO performance.
- No impact on site speed or user experience, ensuring optimal SEO rankings.
- Fully compatible with WordPress, the world's leading content management system.
Please remember to replace [email protected]
with the actual email address you wish to obfuscate.
- WordPress
- PHP
- Email Obfuscation
- Antispambot
- Spam Protection
- Email Harvesting
- Output Buffering
- Regular Expression
- Functions.php
- Mailto Links
Version 1.0.0 Date: 2024-05-08 Works with currenr WP Version
- Added
obfuscate_mailto_links
function to obfuscate all email addresses in mailto links across the site. - The function applies to content in posts, pages, widgets, excerpts, and comments.
- Uses WordPress's antispambot() function to convert email addresses into HTML entities, preventing email harvesting by bots.
- Filters applied:
the_content
,widget_text
,the_excerpt
, andcomment_text
to cover a wide range of outputs.