Support » Plugin: Polylang » [Plugin: Polylang] adding language selector in commercial them

  • Resolved tlesseliers


    I’m using the ifeature theme and selected polylang for the multilanguage feature of the site.

    I’d like to have the language selector in the header of the site, just above the menu. whatever I tried to , I didn’t get the selector (dropdown) to work properly.

    I’ve tried to paste <?php pll_the_languages(array('dropdown'=>1));?>
    into the header.php. The selector appear in the upper left, with no class or div to move it, nor does it do anything, except the dropdown of languages.

    I’ve been reading the documentation, but still don’t get what I’m doing wrong. Can anyone make any suggestions?

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


    You can use the #lang_choice to style the language switcher.

    It is my intention to leave the dropdown with no action as this function is provided for programmers who may want to customize the action themselves. However, you can copy the code used in the widget provided. See polylang/include/widget.php lines 32 to 51


    the style is ok now. thanks!

    In order to get the language selector in the place I want, I had to make some change in the header_actions.php ( once I got it working, I think I will have to create a child theme to do it correctly) . I added:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    seems to be the piece that it doesn’t like: if I comment this part, the js is inserted in the page, but without the urls, so of course nothing happens…

    I don’t know a lot of php, so I don’t know what to do next.

    Thanks in advance.

    Plugin Author Chouby


    Unfortunately your code has been deleted.

    Maybe may statetement above was not exact enough. Try copying this:

    global $polylang;
    foreach ($polylang->get_languages_list() as $language) {
    	$url = $polylang->get_translation_url($language);
    	$urls[] = '"'.esc_js($language->slug).'":"'.esc_url($url).'"';
    $urls = implode(',', $urls);

    and then the lines 39 to 51 which echo the javascript.

    The ‘global $polylang’ is mandatory to access the plugin functions and I simplified the php code to remove the ‘$force_home” option.

    I did not test but hopefully it should work.

    Hi Chouby,

    very nice! It works now. thank you for your advice. didn’t know about the global $polylang 😉

    Now I can focus on translating the content with polylang.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Polylang] adding language selector in commercial them’ is closed to new replies.