Hide main div if wp_nav_menu is empty
Assign the menu to a string: $menu = wp_nav_menu( array ( ‘echo’ => FALSE, ‘fallback_cb’ => ‘__return_false’ ) ); if ( ! empty ( $menu ) ) { echo ‘<div class=”navmain2″>’ . $menu . ‘</div>’; }
Assign the menu to a string: $menu = wp_nav_menu( array ( ‘echo’ => FALSE, ‘fallback_cb’ => ‘__return_false’ ) ); if ( ! empty ( $menu ) ) { echo ‘<div class=”navmain2″>’ . $menu . ‘</div>’; }
You can use the nav_menu_css_class filter to add or remove classes from menu items. Each individual menu item will have this filter applied. An array of classes and the menu item object will be passed to the function, and you will return an array of the classes you want the menu item to have. PHP’s … Read more
I’m going against the majority on this one 🙂 Yes, it can be a good idea to strip it down. Personally I’m keeping only the current-xxx type classes and replacing them with active, and active-parent (for active parent or ancestor items). Why? around the web, active has became the standard class for active menu items … Read more
Okay, I found a solution (and it can be used for any theme, with any plugin as it only uses core WordPress functions). In the menu, name the menu item where you want the user’s name to appear with a place-holder (see screenshot below). Example: #profile_name#, #user#, #random# Now, add the following code to the … Read more
That function just registers new menus. If you want to create a custom type of menu, you need to create your own extended menu walker that would do something custom or activate any other functionality. If you would like to have the top pages listed (in a menu or other situation), you can use wp_list_pages … Read more
Add something like this to the functions file: function current_tag($tags) { global $wp_query; $cid = $wp_query->query_vars[‘cat’]; foreach($tags as $tag) { // match tagid to $cid } } add_filter( ‘get_the_tags’, ‘current_tag’); This won’t work by itself, but it will be a good start for getting the right information to the right place.
Another option is to toggle the CSS Classes checkbox under screen option, WP Admin > Appearance > Menus, and attach the icon to a CSS class. And add your icons using psuedo selectors to the CSS class.
The solution is not to call the same ‘theme_location’ more than once. Theme location is intended to represent an explicit location within the template. Just register a separate ‘theme_location’ for each separate location within the template that you want to display a nav menu. Consider your chosen ‘theme_location’ names to be semantic names, representing the … Read more
Does WP REST API have a built in route for calling menu? Nope, the menu route is not currently (4.9.7) built-in, but there’s a ticket for it in #40878. It’s not mentioned on this REST API roadmap though.
I couldn’t believe there is not a single FREE plugin available that does this. So I wrote my own function. Here you go. Just copy this to your functions.php: function my_breadcrumb($theme_location = ‘main’, $separator=” > “) { $theme_locations = get_nav_menu_locations(); if( ! isset( $theme_locations[ $theme_location ] ) ) { return ”; } $items = wp_get_nav_menu_items( … Read more