Search code examples
wordpresswordpress-themingpolylang

How can I make custom string translations with WordPress plugin polylang?


N.B: I am 15 years old and still learning coding so if you answer me answer me thoroughly please....

Hello everybody, I am making my own website with WordPress I am also making my own custom theme and I am still in it's development, the site is already online but still not complete, and I want to complete it as fast as possible because when school arrive I won't have time to coding anymore.

One of key features of my website that I want it to be a multi language site, at least Arabic and English languages, so I installed the Polylang WordPress plugin and every thing is ok except that there is some texts for example in the footer were hardcoded, written in the footer.php file it self so Polylang can't touch it at all.I want to use Polylang string translations option to translate any text in the header or footer or anywhere I specify it.and this is my problem.

I want a solution to this problem, thanks in advance.

Sorry if there is any language mistakes,and bad layout I am texting from a phone.


Solution

  • I'm not known with Polylang but have used other similar plugins in the past.

    I've viewed the developer documentation here and think you need to use the function pll_register_string to register the string and then use pll_e to output that string.

    So for example you got the text 'Hello World!' in your template, then use the function pll_e to output that text like so:

    <?php pll_e('Hello World!'); ?>
    

    Then to get this string in Polylang string translations you need to register it in your themes functions.php using the pll_register_string function like so:

    <?php
    
      add_action('init', function() {
        pll_register_string('shams-theme', 'Hello World!');
      });
    
    ?>
    

    Hope this helps out, if you need anymore help just let me know.