Hook for Excluding Pages from the Contact Data Encoder
Please note that the Anti-Spam plugin must be installed and activated. This is necessary to use special hooks in WordPress.
The Contact Data Encoder feature of the CleanTalk Anti-Spam plugin protects email addresses and phone numbers 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 your theme's 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( '^/$', // skip encoding on homepage (option 1) '__HOME__', // skip encoding on homepage (option 2) 'page_id=19', // skip encoding on https://website.me/?page_id=19 '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 contact data 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
- All Installation Manuals of CleanTalk Anti-Spam ServiceCleanTalk Anti-Spam Installation Guides Here you can find our plugin installation guides for popular...
- WordPress HooksWordPress hooks Please note that the Anti-Spam plugin must be installed and activated in order...
- Description of All CleanTalk FeaturesAll Features of CleanTalk Anti-Spam Anti-Spam Service - How does Anti-Spam filtering service work Spam...