Hook for Excluding Pages from the Email Encoder
Please note that the Anti-Spam plugin must be installed and activated in order to the special hooks in WordPress.
The Email Encoder feature of the CleanTalk Anti-Spam plugin protects email addresses on your site from spam bots. However, in some cases, you may want to exclude specific pages from protection. For this, you can use the apbct_skip_email_encoder_on_uri_chunk_list hook.
How the hook works:
The hook uses the server variable REQUEST_URI, which contains everything after the domain and before GET parameters. For example:
- URL: https://website.me/hotel-rooms&test-get-param=1 → REQUEST_URI = hotel-rooms
- URL: https://website.me/hotel-rooms/details/&test-get-param=1 → REQUEST_URI = hotel-rooms/details
When checking exclusions, the plugin compares your rules with the REQUEST_URI. If a rule matches part of this string, the Email Encoder will be skipped:
- Rule 'details' excludes https://website.me/hotel-rooms/details/&test-get-param=1.
- Rule 'hotel-rooms/details' also excludes the same page, since it matches the URI.
How to use it:
- Open the functions.php file.
- Add the following code:
add_filter('apbct_skip_email_encoder_on_uri_chunk_list', function($url_chunk_list) { $url_chunk_list = array( 'hotel-rooms', // skip encoding on https://website.me/hotel-rooms 'hotel-rooms/details', // skip encoding on https://website.me/hotel-rooms/details/ 'details', // skip encoding on any URL containing "details" ); return $url_chunk_list; });
In this case all email addresses will remain visible on these pages, while all other pages will stay protected:
- Page https://website.me/hotel-rooms will be excluded from protection (rule: 'hotel-rooms')
- Page https://website.me/hotel-rooms/details/ will be excluded too (rules: 'hotel-rooms/details' or 'details')
Important note:
If you add this code to the main theme’s functions.php, it will be lost after a theme update, and the exclusions will stop working. To ensure the code is preserved, always use a child theme.
It would also be interesting
- WordPress HooksWordPress hooks Please note that the Anti-Spam plugin must be installed and activated in order...
- Encoding Contact Data with a Shortcode and Hook for Third-Party PluginsEncoding Contact Data with a Shortcode and Hook for Third-Party Plugins Please note that the Anti-Spam...
- Hooks for Changing the Contacts Encoder PhrasesHooks for Changing the Contacts Encoder Phrases Please note that the Anti-Spam plugin must be...