Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1342688

    Hi,
    I want to use different menus for different pages and I created the code for functions.php according to this guide:

    The code works as intended, but the wpml language selection, submenu ‘wpml’, is no longer displayed – what am I doing wrong?
    Here is my code for functions.php:

    add_filter( ‘wp_nav_menu_args’, ‘my_custom_wp_nav_menu_args’ );

    function my_custom_wp_nav_menu_args( $args = ” ) {

    if($args[‘theme_location’] === ‘avia’) {
    if( is_page( 734 ) ) {
    $args[‘menu’] = ‘menu home’;
    }
    elseif( is_page( 8590 ) ) {
    $args[‘menu’] = ‘menu home-it’;
    }
    elseif (is_page( 8612, 8683, 8616, 8656, 8644, 8665, 8703, 8713, 8870, 8732, 6679, 8753, 8778, 8785, 8791, 8696, 8770, 8720, 8766, 8747 )) {
    $args[‘menu’] = ‘headermenu komplett it’;
    }
    elseif(is_page( 3981, 8310, 4747, 4737, 8193, 6466, 4143, 4625, 8499, 5111, 4993, 3508, 7840, 7846, 7848, 6002, 8084, 6184, 8070, 8072 ) ) {
    $args[‘menu’] = ‘headermenu komplett’;
    }

    return $args;
    }
    }

    Kindly regards,
    Soltner

    #1342791

    Hey soltner,

    Thank you for the inquiry.

    Did you set the language selector to display on a specific menu? If that it the case, you may need to instead manually insert the language selector using the designated hooks. Please check this documentation for more info.

    // https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/#using-php-actions

    Best regards,
    Ismael

    #1342971

    Hi Ismael,
    yes i set up the language selector as secondary header-menu in the bar above on the right.
    I’ve looked at the documentation, but unfortunately I can’t solve the problem, because my programming skills are relatively limited – can you help me please?

    Best regards,
    Soltner

    #1343265

    Hi,
    Thank you for your patience and the login, I enabled your function and disabled line 153 in your stylesheet to test, I see that you are using the burger menu so the main menu language selectors are hidden. I assume that you want to show the language selectors next to the burger menu so I added this css:

    .js_active.html_burger_menu #header_main #avia-menu > li.av-language-switch-item.language_de,
    .js_active.html_burger_menu #header_main #avia-menu > li.av-language-switch-item.language_it,
    .js_active.html_burger_menu #header_main #avia-menu > li.av-language-switch-item.language_en {
    	display: block;
    }
    

    I also found that your language selectors were duplicating in the header so I added this script to remove the duplicates:

    
    function custom_script() { ?>
        <script>
    const tags = [...document.querySelectorAll('#avia-menu > li.av-language-switch-item')];
    const texts = new Set(tags.map(x => x.innerHTML));
    tags.forEach(tag => {
      if(texts.has(tag.innerHTML)){
        texts.delete(tag.innerHTML);
      }
      else{
        tag.remove()
      }
    })
    </script>
        <?php
    }
    add_action('wp_footer', 'custom_script');

    Now your language selectors are showing and you have different menus on different pages.
    Please clear your browser cache and check.

    Best regards,
    Mike

    #1343442

    Hi Mike,

    Wow, thank you so much for your help – great support, the best ever!
    How can I configure the language switcher? As a dropdown and language list?
    Tried in the language settings of wpml, unfortunately without success.

    Best regards
    Soltner

    #1343486

    Hi,
    Glad to hear this helped.
    The dropdown language selector needs to be assigned to a specific menu, right now it’s assigned to the wpml menu
    2022-03-07_001.jpg
    the wmpl menu is used in the top bar as the Secondary Menu above the header and not in the header.
    But since you are modifying the menus to show a different menu on different pages you won’t be able to choose one main header menu to show the language selector in.

    Best regards,
    Mike

    #1343582

    Hi Mike,
    thanks for your feedback.
    sorry for my late reply, but i was not notified of your reply via email, in the past this was always the case, just for info.

    Then I can’t practically display the language selection as a list of languages ​​or as a dropdown with a language name? Have I understood that correctly? Here I have the problem with the mobile display on the smartphone because the flags cover the logo…

    1) Maybe the only way to resolve the display problem is to configure a language selection in the footer for the smartphone and hide the other one?
    2) or create a custom flag as text for DE IT EN under “Edit Languages”?

    do you have another solution?

    Thanks for your patience,
    I’m grateful for every tip!
    Best regards, Soltner

    #1343635

    Hi,
    Perhaps I can write a script to move the language flags above the logo for mobile only, up to 590px would that work for you?

    Best regards,
    Mike

    #1343660

    Hi Mike,
    that would of course be wonderful – thanks a lot for your effort!

    Best regards,
    Soltner

    #1343748

    Hi,
    Ok I added this to your child theme functions.php

    
    function move_mobile_language_switch() { ?>
        <script>
    (function($) {
    var width = $(window).width();
    if ((width <= 590)) {
    $(".av-language-switch-item").each(function() {
            $(this).appendTo("#header_meta>.container>.sub_menu");
    });
    } else {}
    })(jQuery);
    </script>
        <?php
    }
    add_action('wp_footer', 'move_mobile_language_switch');

    and this to your child theme stylesheet

    #header_meta>.container>.sub_menu>li.av-language-switch-item {
    margin-top: 10px;
    list-style:none;
    }
    #header_meta>.container>.sub_menu {
    	display: flex;
    	justify-content: center;
    }

    please clear your browser cache and check.

    Best regards,
    Mike

    #1343789

    Hi Mike,

    wonderful :-)
    Thank you very much for your effort and quick implementation!

    Have a nice day, best regards
    Soltner

    #1343801

    Hi,

    Great, I’m glad that Mike could help you out :-)

    Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

    #1343873

    Hi Rikard,

    thanks again, you can close the topic!

    Best regards,
    Soltner

    #1343925

    Hi,
    Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Different menu for different pages – wpml language selection not displaying’ is closed to new replies.