The external links are detected for the possibility of changing the URL in a different language. If translating certain external links is not something needed, we can exclude specific domains from being detected by TranslatePress Multilingual by using the following approaches.
- If the external links are generated on the server side using PHP, you can exclude them from detection by adding the attribute ‘data-no-translation-href’ to that anchor node.
For example:<a href="facebook.com" data-no-translation-href>My link</a>
- This code will exclude links that contain the chosen subtexts from being translated dynamically. The code will be effective only for the links changed on the clients side using JS.
/** * You can add a new substring to be excluded by adding in the following code a new substring in the array $excluded_substrings (see the 'example.com' below) * @param $substrings - array that contains already excluded substrings such as 'amazon-adsystem', 'googleads', 'g.doubleclick' * @return array - the array that contains all the substrings, including the ones added in this function, that will be excluded from dynamic translation */ function trpc_add_new_substring_to_be_skipped_from_dynamic_translation($substrings){ $excluded_substrings = array( 'example.com', 'another-example.com' ); // add more here $substrings['href'] = array_merge($excluded_substrings, $substrings['href']); return $substrings; } add_filter( 'trp_skip_strings_from_dynamic_translation_for_substrings', 'trpc_add_new_substring_to_be_skipped_from_dynamic_translation', 10, 1);