- This topic has 13 replies, 3 voices, and was last updated 3 years, 5 months ago by Elvin.
-
AuthorPosts
-
October 28, 2020 at 12:23 pm #1508421Pavla
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>October 28, 2020 at 12:24 pm #1508424Pavlai 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>October 28, 2020 at 2:06 pm #1508534ElvinStaffCustomer SupportIf 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.November 2, 2020 at 12:09 pm #1515145PavlaHi! 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!
November 2, 2020 at 8:26 pm #1515495ElvinStaffCustomer SupportI’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.
November 3, 2020 at 1:46 am #1515700PavlaO.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!
November 3, 2020 at 10:53 am #1516603TomLead DeveloperLead DeveloperHi there,
I’m not sure Elements is the right tool for this.
Have you reported the incompatibility to both WPML and Conditional Menus?
November 4, 2020 at 12:19 am #1517207Pavlahi! 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?
November 4, 2020 at 1:01 pm #1518232TomLead DeveloperLead DeveloperThat depends where you want to add it. Any hook should work if the code for displaying the menu is correct.
November 4, 2020 at 2:17 pm #1518310Pavlai 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
November 4, 2020 at 5:13 pm #1518416ElvinStaffCustomer Supportwhat 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/
November 8, 2020 at 3:36 am #1522321PavlaHi 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!
November 8, 2020 at 10:31 am #1522856Pavlanever 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;
});November 8, 2020 at 11:14 am #1522903ElvinStaffCustomer SupportYeah 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. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.