Support » Plugin: Polylang » Outputing user bio information field

  • Somewhere in a plugin template I’m trying to output my WP users biographic information.

    Polylang filters this field for each language. In normal circunstances it would be enough to use:

    <?php the_author_meta('description', '$id'); ?>

    By using this line in that template I get an empty value.

    Is there more code involved related to Polylang to output each language content?

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


    May be better like this:
    <?php the_author_meta('description', $id); ?>

    Unfortunately it’s not that easy.

    This particular template sits on my child theme. I’m not sure why but it seems that this plugin template runs before Polylang which prevents that this WP function can be filtered by Polylang returning an empty value.

    This field value is empty because Polylang replaces ‘description’ field by ‘description_en’, ‘description_pt’, ‘description_es’ and so on. Each of these filtered fields are filled with information, not the original.

    So the solution I found was:

    $desc_lang = ("description_" . substr(get_locale(), -5, 2));
    the_author_meta( $desc_lang, $id);

    I guess it is reading my browser’s language and not the site’s choosen language.

    Plugin Author Chouby


    get_locale() returns the currently browsed language (not the browser preferred language). You can also use pll_current_language() which will return directly ‘en’, ‘pt’.

    I tried pll_current_language() and had to leave it behind, nothing of Polylang seems to work with this template, possibily because of priorities.

    As far as I understood I’m fine with get_locale() its doing the same job as pll_current_language().

    The only reason I can find for Polylang behave as it never existed with this plugin must be related with the Ajax call it has.

    Plugin Author Chouby


    For ajax calls on frontend, you just have to set the variable ‘pll_load_front’ in the request either as POST or GET. You can optionally set the ‘lang’ variable (with the language code) to load a specific language instead of the current language.

    Exactly, now I have Polylang API back for this plugin, it was an Ajax call that was hiding it.

    Google is really friendly when it comes to get good answers. I found this here

    function gce_load_polylang_on_ajax() {
    <script type="text/javascript">
    if (typeof jQuery != 'undefined') {
    		data: { pll_load_front: true }
    add_action( 'wp_head', 'gce_load_polylang_on_ajax' );

    With this function that I’ve pasted at my child theme functions.php there’s no need to hardcore .js files at least to set the variable ‘pll_load_front’ in the request.

    The cherry in the top of the cake would be to extend that function to set the ‘lang’ variable with the ‘pll_current_language()’, which I don’t have any idea of how it could be done.

    I’ve tried one thing but couldn’t go any further, which was get the language statement at the begining of the document (eg.)'<html lang=”fr-FR” …. > and set the whole display result with that.

    lang: document.getElementsByTagName('html')[0]

    It would return fr-FR for the example above and is consistent with our frontend wanted language, instead of the wp-config.php defined language.

    So for now I’m using Polylang API that hopefuly will solve the whole thing.

    Plugin Author Chouby


    The cherry in the top of the cake would be to extend that function to set the ‘lang’ variable with the ‘pll_current_language()’, which I don’t have any idea of how it could be done.

    It shouldn’t be necessary as, in the ajax response, by default Polylang will choose the language from the cookie which is equivalent as forcing the language with pll_current_language().

    You’re absolutely right as always.

    In my case it’s not happening that way because I have WP Native Dashboard plugin installed which is interfering.

    For example:

    <a href="" title="<?php echo __('My text', 'my-text-domain'); ?>">

    The result translation is in backend defined language or default language if user isn’t logged in.

    By deactivating the plugin it gets working fine.

    Also tried to register a string with pll_register_string and then use instead:

    <a href="" title="<?php pll_e('My text'); ?>">

    The result is the same.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Outputing user bio information field’ is closed to new replies.