• Multiple language switchers on a same page using PLL_Widget_Languages are not working, because all the widgets are created with an identical id attribute and the JavaScript hence only reacts to the first element clicks. The code behind seems to almost support using custom id set with the args array, but not quite. More elaborately:

    I tried to create a second widget with the following:

    the_widget('PLL_Widget_Languages', array(
      'id' => 'lang_choice_custom_id',
      'name' => 'lang_choice_custom_id'
    ));

    And the PLL_Walker_Dropdown eventually creates the <select> with correct ID:

    <select name="lang_choice_custom_name"  id="lang_choice_custom_id">
      <option value="en" selected="selected">English</option>
      ...
    </select>

    But the problem is, the JavaScript snippet the widget creates uses a hard-coded id parameter (include/widget-languages.php:54):

    var d = document.getElementById('lang_choice');

    This is easily corrected, if you just add a line before the JavaScript:

    $id = $instance['id'];

    And then change that to the JavaScript line with embedded PHP variable:

    var d = document.getElementById('{$id}');

    https://www.ads-software.com/plugins/polylang/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Elmo Allen

    (@elmo5)

    Edit: you need to of course also take into account the default case, if the id parameter is omitted, i.e., e.g.:

    ′$id = isset( $instance[‘id’] ) ? $instance[‘id’] : ‘lang_choice’;`

    Thread Starter Elmo Allen

    (@elmo5)

    I wonder if this is going to be corrected any time soon. I think it is a bug, not just a missing feature, because PLL_Widget_Languages offer the possibility for a custom element ID, but the JQuery part ignores that.

    Plugin Author Chouby

    (@chouby)

    Hi!

    I missed this topic when you created it. I will not fix that in 1.6.x branch, but it will be fixed in v1.7. I plan to make a beta available in the first half of February.

    Thread Starter Elmo Allen

    (@elmo5)

    Sounds good!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple language switchers not working because of hard-coded id’ is closed to new replies.