• Resolved itzelm

    (@itzelm)


    Hello, i follow instructions to add the code to the header and functions php. this is what i added.

    Insert some code – for example like this –

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    <select id="msls_languages">
    <?php if (function_exists ('the_msls')) the_msls (); ?>
    <select>

    in your header where you would like to have the drop-down. In your functions.php insert a function like this

    function my_msls_output_get( $url, $link, $current ) {
        return sprintf(
            '<option value="%s"%s>%s</option>',
            $url,
            ( $current ? ' selected="selected"' : '' ),
            $link
        );
    }
    add_filter( 'msls_output_get', 'my_msls_output_get', 10, 3 );

    however, when i click a language in the dropdown menu, the link does not work. in other words, if i am in the english version of the site and i click “spanish”, the label in the dropdown changes to “spanish” but the spanish version of the page does not changes. What could be the problem?

    Thanks

    https://ww.wp.xz.cn/plugins/multisite-language-switcher/

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

    (@realloc)

    I guess that you have to add also some JavaScript where you change the location.

    Could you give me the link to the page you mentioned?

    Thread Starter itzelm

    (@itzelm)

    Thanks here is the page http://www.e-contentinternational.com

    Plugin Author Dennis Ploetner

    (@realloc)

    OK, please close the select first. šŸ˜‰

    <select id="msls_languages">
    <?php if (function_exists ('the_msls')) the_msls (); ?>
    </select>

    After that use some JavaScript like here:

    http://stackoverflow.com/questions/5150363/onchange-open-url-via-select-jquery

    Thread Starter itzelm

    (@itzelm)

    Thanks for your response.

    I closed the select tag. I also added the Javascript immediately after the </select>. It still does not work.

    I find interesting that a few weeks ago, I followed the same instructions and was able to make it work (without the dropdown option). But then I needed to reinstall the template and the header and functions page were replaced. So, I had to add the code again. This time it does not work.

    Plugin Author Dennis Ploetner

    (@realloc)

    OK, almost finished. šŸ˜‰

    <script>
        $(function(){
          // bind change event to select
          $('#msls_languages').bind('change', function () {
              var url = $(this).val(); // get selected value
              if (url) { // require a URL
                  window.location = url; // redirect
              }
              return false;
          });
        });
    </script>

    Just change the id to msls_languages.

    Cheers,
    Dennis.

    Thread Starter itzelm

    (@itzelm)

    No success. Let’s review. I added this to the functions.php

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    function my_msls_output_get( $url, $link, $current ) {
    return sprintf(
    '<option value="%s"%s>%s</option>',
    $url,
    ( $current ? ' selected="selected"' : '' ),
    $link
    );
    }
    add_filter( 'msls_output_get', 'my_msls_output_get', 10, 3 );

    in the header page I added this

    <select id="msls_languages">
    <?php if (function_exists ('the_msls')) the_msls (); ?>
    </select>

    Immediately followed by this

    <script>
        $(function(){
          // bind change event to select
          $('#msls_languages').bind('change', function () {
              var url = $(this).val(); // get selected value
              if (url) { // require a URL
                  window.location = url; // redirect
              }
              return false;
          });
        });
    </script>

    Still not working.

    Plugin Author Dennis Ploetner

    (@realloc)

    You should use tools like Firebug when you work on your site. Using a tool like this indicates TypeError: $ is not a function so you should change the JavaScript code like this

    <script>
        jQuery(document).ready(function( $ ) {
          // bind change event to select
          $('#msls_languages').bind('change', function () {
              var url = $(this).val(); // get selected value
              if (url) { // require a URL
                  window.location = url; // redirect
              }
              return false;
          });
        });
    </script>

    I will maybe add support for a select in future versions of the Multsite Language Switcher.

    Cheers,
    Dennis.

    Thread Starter itzelm

    (@itzelm)

    Yea, thanks. It works. You are awesome!

    Of course I will donate to your plug in. šŸ™‚

    Plugin Author Dennis Ploetner

    (@realloc)

    Even better: https://github.com/lloc/MslsSelect šŸ˜‰

    Plugin Author Dennis Ploetner

    (@realloc)

    And now also in the WordPress Plugin Directory: MslsSelect.

    Cheers,
    Dennis.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘language dropdown in header not working’ is closed to new replies.