Home » How to make any theme/plugin compatible with Polylang

How does Polylang know which strings to translate?

If you’ve ever worked with Polylang you might’ve come across an instance in which you weren’t able to translate a certain plugin/theme string simply because it wasn’t registered in Polylang by the plugin/theme author.

This is frustrating because now we aren’t 100% able to translate our website. What if I tell you there’s actually a way to make Polylang work in these instances.

Normally what happens when using i10n (internationalization) to translate a plugin/theme an author wraps strings within a function. This could be either




, well, there’s a few of them. Check out the wordpress codexPolylang has their own function to render strings,




. Read more about these function here.Before Polylang is able to output these strings, they should first be registered by using


. So how do we translate strings that are outputting via the first set of functions that I talked about. Well let me show you.

The minimum requirements

Before any of this can work we have to make sure that the plugin/theme author has followed the proper i10n rules. Just to be certain, open the plugin files and make sure the string you are trying to translate is wrapping in any of these functions

In my example I’m going to use YITH WooCommerce Gift Cards. This plugin has been made ready for i10n, but isn’t compatible with Polylang.

As shown in this example, some of the strings have been automatically translated when activating Polylang, but other strings are persistent and do not get automatically translated.

Untranslated strings

So, how do we translate these strings?

To make actually work we are going to inject the Polylang translation function with the



function polylang_translate_incompatible_strings(
) {
    if ($domain === "yith-woocommerce-gift-cards") {
        return pll__($translated);
    return $translated;

add_filter("gettext", "polylang_translate_incompatible_strings", 999, 3);

Let’s talk about what is happening here. You’ll notice that we are hook into


, which gives us 3 variables:

$translated, $untranslated, $domain

, these speak for themselves. We’re then doing a check to see if the current text domain is equal to the text domain of our incompatible plugin/theme. In our case


. If it is equal, we then wrap our


string within the Polylang translate function


. If it’s not equal to the text domain, we just return the translated string.

Before this function will work, we first need to register our strings within Polylang.

add_action("init", function () {
            "Set an amount",
            "Yith Woocommerce Gift Cards"
            "Enter a message for the recipient",
            "Yith Woocommerce Gift Cards"
            "Add to cart",
            "Yith Woocommerce Gift Cards"
}, 9999);

Hook into the


action hook and register all the incompatible strings. Note that I used a priority of


. This is because in some cases taking a low priority doesn’t work, so just to be safe, take it up a notch.

When done correctly you should now be able to translate your strings.

Translated strings

Do you have any questions? Please feel free to leave a comment below, and I will do my best to respond as quickly as possible.

If you’re interested in more tutorials or engaging content, be sure to check out my YouTube channel

Laat het weten als er
Inline feedbacks
Bekijk alle reacties
Zou graag je mening willen weten, laat een reactie achter.x