New Landing How can we help? Themeforest Theme Support Joyn language dropdown in menu

Viewing 8 posts - 1 through 8 (of 8 total)
  • Posted in: Joyn
  • #251059
    makemakes
    Member
    Post count: 120

    Hi all,

    I’d like to add the wpml language dropdown to my menu. If you have 1 menu this is no problem you can just check the checkbox and select in the dropdown in WPML to which menu you would like to add this. It also adds smoothly to the translated version of this menu.

    BUT ! if you have 2 menus (cfr. my other thread) because your homepage has another menu than the other pages. Because it has some onepager links which don’t work if I use the same menu on the other pages.

    How can I add: <?php do_action(‘wpml_add_language_selector’); ?> too all menu’s ? It just can be the last item in the row in the navigation.

    Tnx !

    #251219
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please paste this code at functions.php of child theme.

    // Filter wp_nav_menu() to add additional links and other output
    function wpml_custom_menu($items,$args) {
     
        if (function_exists('icl_get_languages') && $args->theme_location == "primary" ) {
            $languages = icl_get_languages('skip_missing=0&orderby=name');
     
            $current_language = $languages[ICL_LANGUAGE_CODE];
     
            $items .= '<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children mega-with-sub ss-nav-menu-item-4 ss-nav-menu-item-depth-0 ss-nav-menu-reg um-flyout-align-center"><a href="' .$current_language['url']. '"><img src="' . $current_language['country_flag_url'] . '" /> ' .$current_language['native_name'] . '</a><ul class="sub-menu sub-menu-1">';
             
            unset( $languages[ICL_LANGUAGE_CODE] );
            foreach( (array)$languages as $language ) {
                $items .= '<li class="menu-item menu-item-type-post_type menu-item-object-page ss-nav-menu-item-depth-2"><a href="' . $language['url'] . '"><img src="' . $language['country_flag_url'] . '" /> ' . $language['native_name'] . '</a></li>';
            }
     
            $items .= '</ul></li>';
        }
          
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'wpml_custom_menu',10,2 );

    Thanks
    Mohammad

    #251227
    makemakes
    Member
    Post count: 120

    I did this, didnt see anything change, tried to reactivate it in wpml, but it’s only in one of the menus, not both :/

    Or how do I need to use it? (in my initial post there’s credentials)

    #251533
    makemakes
    Member
    Post count: 120

    are you guys working on this? I have the white screen of death now, and i haven’t touched it?

    #251537
    makemakes
    Member
    Post count: 120

    white screen is fixed, but still have the issue of the language dropdown to be set in 2 menu’s 🙂

    #251539
    makemakes
    Member
    Post count: 120

    fuck it did work, i had some spaces that shouldn’t be there in the functions.php

    tnx!!!

    #251545
    makemakes
    Member
    Post count: 120

    I was too quick, it isn’t resolved, still not seeing the menu in both menus. code is in functions.php

    #251937
    David Martin – Support
    Moderator
    Post count: 20834

    The code above is looking for the menu location Primary, $args->theme_location == "primary" where are you using this new menu.

    You’re better off contacting WPML as this is a generic query for their plugin. https://wpml.org/forums/forum/english-support/

    – David.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register