Support » Plugin: Polylang » pll_e() / pll__() on functions.php = KO

  • Resolved marcreig



    I’ve a problem:

    – I load via AJAX a group of posts when “load more posts” button is pressed.
    The function defined on functions.php to handle the ajax request, returns an HTML block with the fresh loaded posts. This HTML is basically the same that appears on my index.php, on my theme. So posts loaded on index.php and the ones returned via functions.php have the very same structure and code.

    Problem is:

    – On index.php, functions from polylang work properly. But in functions.php, they don’t.
    I’m still having my registred words in english instead of spanish.

    Why is that?


    PS: fact is, that in functions.php I’ve some defined filters (like one to short the excerpt words number to 15 words) and they doesn’t work at all too. What is going on?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Chouby


    There are in fact two questions:

    1. Can we use pll__ and pll_e in functions.php?
    Yes, but you must wait for the language to be set. In your polylang settings, you can choose two options: setting the language from content or from url. In the first casse, the language is set quite late. See at then end of

    2. Does Polylang load correctly when doing ajax on frontend?
    Not by default. You must set the variable ‘pll_load_front’ in your ajax request for Polylang to detect what to do. See the same page in the documentation.

    Well then, I’ve done this:

    1) Changed option to number 2, which is appending the language on every single URL.
    Nothing changed. Keep recieving block in English when I’m working in Spanish on web’s home.

    2) On AJAX request, I’ve added on data block for the POST request the variable “pll_load_front”.
    And I’ve tried like this:

    `$.post(AdminAjax.ajaxurl, { action: “loadMorePosts”, cont: cont, ptype: ptype, pclass: pclass, offset: offset, pll_load_front: true }).done(function(data) {
    //alert(“Data Loaded: ” + data);


    And I’ve tried like “pll_load_front: ‘pll_load_front'” too.
    Nothing happened.

    Keep recieving in both cases texts in english.

    So, could you explain me the exact steps I should take to make it work please?

    Thank you so much! 🙂



    Since I’ve added on ajax request pll_load_front: 1, now when I push the button to load more posts, I get this error:

    Fatal error: Call to undefined method Polylang_Core::register_string() in …….

    So I guess that adding pll_load_front: 1 has done something at last (I’ve cleared the cache to see that it was really doing something). But now, it works no more. If I remove pll_load_front: 1, then everything works normally.


    Plugin Author Chouby


    The fatal error should be fixed in the current development version (

    Is your theme freely downloadable?

    Well, yes. I’ve used the STARKERS empty (blank base) theme, to do and create my own theme. From very scratch.

    So everything is ok, I think so.

    So right now, what should I do?
    I mean, can I recieve translated posts or not?

    Will you publish the update without being a development unit, soon?


    Plugin Author Chouby


    Can you send me your theme that I can try to find out where’s the issue? You can post a link (or your email) here

    I’ve changed nothing. I’ve created my index and whatever… but I’ve not modified anything in general.

    So you try! 🙂


    Plugin Author Chouby


    Yes. I already downloaded it. Google is my friend 😉 But if I well understood, your problem is that Polylang does not act as you expect with the modifications you made (what you did to get posts in ajax). So I can’t find out what’s wrong by testing only the unmodified theme.

    I’ve modified nothing at all…
    I’ve just made a JS file with the respective jQuery $.post(…) call, with some data which I’ve showed you before, and that’s it!
    On functions.php, I’ve the function which does the WP_Query call and it’s over!


    Anything new?

    As I said, I’ve made no modification to original theme.
    Just functions.php with the function to be called and the call on a site.js. That’s it.

    Oh and for if it’s useful, I’ve this over the function:

    add_action( 'wp_ajax_nopriv_loadMorePosts', '_loadMorePosts' );
    add_action( 'wp_ajax_loadMorePosts', '_loadMorePosts' );


    Oh wow man! I’ve recently seen that there was a new Polylang update! And you know what? Now it works!! No more PHP error there! :_)
    Thanks man! Don’t know what you’ve resolved (I guess file dependencies on load time…) but now it works wonderfully! 😉

    It’s over! 🙂

    It was the update what resolved it!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘pll_e() / pll__() on functions.php = KO’ is closed to new replies.