How to add new string in Polylang
Last updated
Last updated
In order for Polylang to know what to translate, it is necessary to register the words that need to be translated. Polylang, by default, withdraws all the words that it believes should be translated and placed in Strings Translations. However, the problem is the words that Polylang does not see as the words to be translated.
Here is an example of the words that I added in Strings Translations, which Polylang did not immediately withdraw, can be seen to be important words that should also be translated:
Here’s what you need to do. Find the string that you need to be registered. I need to register Sign Out, so I went to header.php (file in the child theme) and found the row containing:
<?php _e('Sign Out', 'golo-framework'); ?>
Therefore, you need to register Sign Out. When you find out, go to functions.php (file in the theme) and add the following line to the bottom:
pll_register_string('golo-framework', 'Sign Out', 'true');
From that moment, the Sign Out string is located in Strings Translations and you can add translations for the languages that you have set up in Polylang.
Go to Strings Translations and add translations for the new string:
Quite simply, but that’s not enough. Now we have made Polylang aware of what the words should offer the translation we have inserted, but Polylang still does not know where to show these words. You need to do the following.
Return to the header.php file and replace:
<?php _e('Sign Out', 'golo-framework'); ?>
Instead, place:
<?php echo pll_e('Sign Out')?>
And that is that. Now you have informed Polylang that the Sign Out option should change depending on the language that is selected on the site.
This procedure should be repeated for each word-string to be translated. Keep in mind that strings are in different theme files, and all the strings can be registered through the functions.php file.