[Support request] menu keyname

Home Forums Support menu keyname

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

    Hi! I am trying to fix an issue with wpml and conditional menus (https://wpml.org/forums/topic/bug-with-conditional-menus/#post-3138540) But in order to do it i need the keyname of the primary menu and the off canvas menu. i need to replace it in an xml file but i just cant figure out the keyname for those two menus.. could you help me out with that?

    <wpml-config>
    <admin-texts>
    <key name=”theme_mods_twentyseventeen”>
    <key name=”themify_conditional_menus”>
    <key name=”top”>
    <key name=”1″>
    <key name=”menu”/>
    <key name=”condition”/></key>
    <key name=”2″>
    <key name=”menu”/>
    <key name=”condition”/></key>
    </key>
    </key>
    </key>
    </admin-texts>
    </wpml-config>

    #1508424
    Pavla

    i guess it would be something like this

    wpml-config>
        <admin-texts>
            <key name=”theme_mods_generatepress”>
                <key name=”themify_conditional_menus”>
                    <key name=“primary”>
                        <key name=”1″>
                            <key name=”menu”/>
                            <key name=”condition”/></key>
                        <key name=”2″>
                            <key name=”menu”/>
                            <key name=”condition”/></key>
                    </key>
                </key>
            </key>
        </admin-texts>
    </wpml-config>

    #1508534
    Elvin
    Staff
    Customer Support

    If you want to see all the details about your menu, you can do a var_dump of it.

    try this PHP snippet out.

    add_action('generate_before_header',function(){
    $locations = get_nav_menu_locations(); //get all menu locations
    $menu = wp_get_nav_menu_object($locations['primary']);//get the menu object
    
    echo '<h2>The name of the menu is <em>"'.$menu->name.'"</em></h2><br/><h3>var_dump of primary menu down below</h3><br/> '; // name of the menu
    var_dump($menu);
    });

    This code displays a var_dump() of your primary menu after the header. It should display every detail you need, i.e: menu id, name, slug.

    A wise man once said:
    "Have you cleared your cache?"

    #1515145
    Pavla

    Hi! I tried that but this seems to put out the specific menus, which i dont need (they have numbers) and not the keyname of the primary menu and the offcanvas menu.
    any other suggestions, please?

    thanks!

    #1515495
    Elvin
    Staff
    Customer Support

    I’m not sure I understand what you need.

    To clarify: Do you need the names/slugs of the menu locations? if that’s the case you can var_dump(get_nav_menu_locations());

    To list the most used ones: primary, slideout & secondary.

    If you only need the name of the menu on a specific location, you can use these for var_dump:
    wp_get_nav_menu_name($locations[‘primary’]); or wp_get_nav_menu_name($locations[‘slideout’]); or wp_get_nav_menu_name($locations[‘secondary’]);

    If you need the values tied to the menu items of a menu on a specific location like primary menu, you can var_dump(wp_get_nav_menu_name($locations['primary']));

    References:
    https://developer.wordpress.org/reference/functions/get_nav_menu_locations/
    https://developer.wordpress.org/reference/functions/wp_get_nav_menu_name/
    https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/

    All that said, there must be a value returned by these that you can use for what you’re trying to do.

    A wise man once said:
    "Have you cleared your cache?"

    #1515700
    Pavla

    O.k. thats what i needed, thank you!
    But unfortunately the fix posted on WPML is nos working as its really old and not compatible with the conditional menu plugin actual version.
    Do you maybe have an workaround using the generaptepress elements to generate conditional menus?

    what I want to achieve is, e.g. all posts with the category “XY” show instead of the main menu the menu “xy_menu”.

    thank you!

    #1516603
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    I’m not sure Elements is the right tool for this.

    Have you reported the incompatibility to both WPML and Conditional Menus?

    #1517207
    Pavla

    hi! Yes, And i’m with this already for four months they won’t give a new solution.

    I Think if i could somehow display the menu with a Hook i could work it out. What would be the Hook for displaying a menu?

    #1518232
    Tom
    Lead Developer
    Lead Developer

    That depends where you want to add it. Any hook should work if the code for displaying the menu is correct.

    #1518310
    Pavla

    i dont know what the hook for displaying a menu is, thats why i ask…

    i would want it as similar as it is like now on my webpage, did you have a look at it? its the primary menu in the header.

    thanks

    #1518416
    Elvin
    Staff
    Customer Support

    what I want to achieve is, e.g. all posts with the category “XY” show instead of the main menu the menu “xy_menu”.

    If this is what you’re trying to do you can try using PHP snippets like this:

    add_filter( 'wp_nav_menu_args', function ( $args = '' ) {
    	if( $args['theme_location'] == 'primary' && is_category('your category here') || ( is_single() && in_category( 'your category here' ) ) ) { 
    		$args['menu'] = 'menu id here'; 
    	}
    	return $args;
    });

    What this code does is it changes the menu used on your primary menu when in the specified category archive page and posts in the specified category.

    But ofcourse you can change the if condition to apply to specific pages only.

    Here’s how to find your menu id. https://wpexplorer-themes.com/total/docs/find-menu-id-wordpress/

    A wise man once said:
    "Have you cleared your cache?"

    #1522321
    Pavla

    Hi Elvin! Fantastic, I got it running, but it works only on single posts. I have also Pages assigned to the same categories, can I make it work for both?

    thank you so much for your help!

    #1522856
    Pavla

    never mind, it seems i figured it out, even though i have none skills in php 😀

    does it seem alright to you? I seems to work.

    add_filter( ‘wp_nav_menu_args’, function ( $args = ” ) {
    if( $args[‘theme_location’] == ‘primary’ &&
    is_category(’65’) || ( is_single() &&
    in_category( ’65’ ) )or
    is_category(’65’) || ( is_page() &&
    in_category( ’65’ ) )){
    $args[‘menu’] = ‘928’;
    }
    return $args;
    });

    #1522903
    Elvin
    Staff
    Customer Support

    Yeah that’s right.

    To clarify and interpret the code:

    What that does is, if the menu’s theme location is “primary” and the page it is in is of category archive page “65” or it is a single post under category “65” or a page under category “65”, use menu with the id of “928”.

    Glad you figured it out. 🙂

    A wise man once said:
    "Have you cleared your cache?"

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.