Encoding Contact Data with a Shortcode and Hook for Third-Party Plugins

 

Please note that the CleanTalk Anti-Spam plugin must be installed and activated for these special hooks to function.

This article explains how to use CleanTalk's shortcode and hook features to encode and protect contact details on your website. This feature is ideal for web developers and site administrators looking to shield sensitive contact details such as email addresses or phone numbers from automated scraping bots without disrupting the experience for real visitors.

Even if the global Encode contact data option is turned off, these methods remain active and will function for logged-in users as well.

 

Add the following code directly into your content using the visual editor:

[apbct_encode_data]any text to encode[/apbct_encode_data]

You can also add some attributes to customise output (hide encoded text under "*" symbol)

[apbct_encode_data mode="obfuscate"]any text to encode[/apbct_encode_data]

Alternatively, you can add some attributes to customise output (hide encoded text under your custom text)

[apbct_encode_data mode="replace" replacing_text="click-to-decode"]any text to encode[/apbct_encode_data]

This will encode the specified text so it appears hidden to bots on the public site. Legitimate users can decode the information by clicking on it, similar to encoded email links. 

Important: the shortcode does not work inside HTML tags.

 

For developers, the hook apbct_encode_data provides a flexible way to encode any data from source code. Wrap any text you want to encode with this hook, like so:

function encode_contact_data_example() {
$encoded_text = apply_filters('apbct_encode_data', 'any text to encode');
echo $encoded_text;
}
add_action('wp_footer', 'encode_contact_data_example');

The $encoded_text variable will store the securely encoded text. Once displayed on the page, legitimate users can easily access it with a click, while it remains entirely invisible to scrapers and bots.

 

You can see the result below:

Result

These methods allow you to control exactly what information is exposed to automated bots, ensuring your real visitors can access encoded contact details without any issues.

 

 

While the CleanTalk Anti-Spam plugin's Contact Data Encoder feature protects your site's email addresses and phone numbers from scrapers, you may occasionally need to bypass this feature on certain pages. To exclude specific pages from protection, you can utilize 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: adding this code to your parent theme's functions.php file means it will be wiped out whenever the theme updates, which will break your exclusions. To prevent this and keep your code safe, always implement these changes within a child theme.

 

 

Since version 6.52 of the Anti-Spam by CleanTalk plugin, you can change some of the Contact Data Encoder phrases. Three phrases are available for modification via hooks, which are displayed to users in a modal window when data is being decoded:

  1. The magic is on the way!
  2. The complete one is ...
  3. Please wait a few seconds while we decode the contact data.

The following hooks can edit those phrases:

  1. apbct__ee_wait_for_decoding_text
  2. apbct__ee_original_email_text
  3. apbct__ee_decoding_process_text

To change the phrases, add the hook handlers to your functions.php file.

 

The example:

add_filter('apbct__ee_wait_for_decoding_text', function ($_original_text) {
 return 'Other text for `wait for decoding`';
});
add_filter('apbct__ee_decoding_process_text', function ($_original_text) {
 return 'Other text for `decoding process`';
});
add_filter('apbct__ee_original_email_text', function ($_original_text) {
 return 'Other text for `original email`';
});

 

You can see how the modified phrases appear in the attached screenshots.

Mofided Phrase

Mofided Phrase

 

Was this information helpful?

It would also be interesting

Copied to clipboard