WordPress.org

Forums

Polylang
[resolved] adding language selector in commercial them (5 posts)

  1. tlesseliers
    Member
    Posted 2 years ago #

    Hi,
    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?

    http://wordpress.org/extend/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    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

  3. tlesseliers
    Member
    Posted 2 years ago #

    Hi,

    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.

  4. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  5. tlesseliers
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic