Introduction
In many WordPress projects, there is a need to translate not only standard interface elements like titles, menus, or post content but also custom strings located, for example, in the header or footer. Polylang is one of the most popular plugins for implementing multilingual functionality. However, it does not natively support translating custom strings directly embedded into templates. In this article, we’ll explore how to manually register such strings using Polylang.
Polylang is a WordPress plugin that enables multilingual websites. It allows users to translate posts, pages, media, categories, tags, and more. Key features:
- Simple interface for adding translations.
- Support for multiple languages.
- Integration with popular themes and plugins.
- Language switcher functionality.
Limitations:
- Custom strings in templates are not translated by default.
- Manual registration of such strings is required.
Registering Custom Translation Strings
To register multiple strings you need to edit functions.php file. I use theme twentytwentytwo so file located there: /var/www/html/wp-content/themes/twentytwentytwo/functions.php
I connected to my server and edited file using nano editor:
sudo nano /var/www/html/wp-content/themes/twentytwentytwo/functions.php
I created a list of fields to make my further fork easier. I put php function code on the end of file:
// Add Polylang translate function
function register_custom_polylang_strings() {
$strings = [
'Custom 1:' => 'Custom Labels',
'Custom 2:' => 'Custom Labels',
'Custom 3:' => 'Custom Labels',
'Custom 4:' => 'Custom Labels',
'Custom 5:' => 'Custom Labels'
];
foreach ( $strings as $string => $group ) {
pll_register_string( sanitize_title($string), $string, $group );
}
}
add_action('init', 'register_custom_polylang_strings');
In future you can change these fields to make identification of translation. It is just sample. After saving file and reloading page you can see these fields in the translations list.

Creating a Translation Shortcode
Easy way to get translation data is a creating a translation shortcode. Add a shortcode to the same functions.php
to display registered strings
function pll_translate_shortcode($atts) {
$atts = shortcode_atts([
'text' => '',
], $atts);
return pll__($atts['text']);
}
add_shortcode('tr', 'pll_translate_shortcode');
You need to save this file and reload WordPress admin page to see changes.
In this case we will use shortcode like this:
[tr text="Custom 1:"]
Caution: If you change name of field in the function, you need to change it in wordpress, where you use it.
Adding Translation
So we can see custom fields and we need fill it with two languages:
- Go to Languages → Translations in the admin panel.
- Locate the group Custom Labels.
- Find the string (e.g., custom-1:).
- Add translations:
- In Ukrainian: Перемикач мов:
- In English: Language switcher
- Save changes.

Using shortcode in a Template
You can now use the shortcode in any template location, such as the footer. Select shortcode block and add the code:
[tr text="Custom 1:"]
Save template and reload page to see result. It is perfect.

Result looks like for Ukrainian and English languages. Next you can use custom style to change design of this block.


Conclusion
Although Polylang lacks out-of-the-box support for translating custom strings, this limitation is easily overcome with manual registration via functions.php
and shortcode implementation. This method enables full multilingual support even in complex or custom WordPress templates.