I'm doing some maintenance on a website. I thought it was easy but I can't display submenu. The costumer said that the template was developed for them so probably the submenu feature was not included in it.
I don't know much php (actually I know very few) and I can't find a solution on google. I can use html and css pretty well to style it but before I need it to display.
here is the code I have in the header.php:
<span id="toggle_nav" class="icon-menu"></span>
<?php wp_nav_menu( array( 'theme_location' => 'main-navigation', 'container' => false, 'menu_id' => 'nav', 'menu_class' => '', 'link_after' => '', 'depth' => 1, 'fallback_cb' => false ) ); ?>
Thanks in advance,
Daniele
The comment from Ash Patel was indeed the right solution:
'depth' => 1
to
'depth' => 0
Related
I'm having troubles removing the WordPress wrapper div from my wp_nav_menu(). I've passed container => false to my menu args but the div keeps displaying. I'm using the following arguments:
$defaults = array(
'container' => false,
'theme_location' => 'menu',
'menu_class' => 'main-nav',
);
wp_nav_menu( $defaults );
I have also declared the menu in my functions.php file.
register_nav_menus( array(
'main-nav' => __( 'Main Nav', 'ldsshop' ),
));
I have used these arguments with previous themes with no problems, but in this instance the wrapper keeps displaying, and I'm at a point where I need some extra eyes and help, no doubt I've missed something.
Thanking you all in advance,
Stu :)
Use container empty like this
'container' => '',
So it will like this
$defaults = array(
'container' => '',
'theme_location' => 'menu',
'menu_class' => 'main-nav',
);
wp_nav_menu( $defaults );
It will work, even it's working on my hand.
Update About Solved This Question
Try to the following using array in wp_nav_menu
wp_nav_menu( array(
'theme_location' => 'menu',
'container' => '',
'menu_class' => 'main-nav'
) );
use same '' about container if false not to work
Here is an article finding some helpful
See more in the codex https://developer.wordpress.org/reference/functions/wp_nav_menu/
In my case "container" => false doesn't work, It only works when you write "items_wrap" => "%3$s" but it removes all wraps including <ul> if you want to remove <div> and have your menu wrapped in <ul> I recommend to do this way
wp_nav_menu(array(
'theme_location' => 'header_menu',
'menu' => 'header_menu',
'items_wrap' => '<ul>%3$s</ul>',
'container' => false,
'menu_class' => 'nav',
'list_item_class' => 'nav-item',
'link_class' => 'nav-link',
'menu_id' => 'menu-main-menu'
));
I've used a HTML 5 Blank template and converted it to a WordPress theme successfully.
But when I use this code: <?php html5blank_nav(); ?> to auto populate the main navigation it of course looses the template styling.
I've enqueued all the css but from what I understand I need to use the below code to tell the menu how to be styled:
PHP:
function html5blank_nav()
{
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
}
If you take a look at http://geekcloud.co.uk - this is the header navigation menu style im trying to achieve using this code: .
Any help would be greatly appreciated.
Thank you.
You might want to look into the wp_enqueue_style page on the Wordpress developer documentation.
You have to register the stylesheet in your functions.php file with
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Good luck developing!
Im starting with wordpress and I have a problem with a menu Im doing. In functions.php, I have this:
register_nav_menus(array(
'principal' => 'principal_bar'
));
Very simple. Now, in my header.php, I have this:
wp_nav_menu(array(
'container' => false,
'items_wrap' => '<ul>%3$s</ul>',
'theme_location' => 'principal',
'menu_class' => 'nav navbar-nav navbar-right'
));
As you can see, Im (trying) to use bootstrap classes in my menu. The thing is that when I edit my menu in the wordpress visual interface, the menu_class of my menu is removed (in Inspector, the ul ends with no class), and obviously the visual aspect of my menu is totally broken. My answer, Did I miss something? All tutos give the same way to do menus, but mine is not taking the classes at all. Am I doing something wrong here? Or is a problem bootstrap-wordpress? I am really confused right now... Thank you very much for your help...
You missing some properties in you items_wrap, should be:
wp_nav_menu(array(
'container' => false,
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'theme_location' => 'principal',
'menu_class' => 'nav navbar-nav navbar-right'
));
Looking at the Wordpress code I am struggling to find where the menus are been put together, (to be rendered).
For example, if I want to output 'menu-1' where is the function/class that creates the output result?
Does it use a class to do the creation? Does it follow a specific pattern?
Walker_Nav_Menu And wp_nav_menu is behind the wordpress Navigation. According to your requirement you need to customize the wp_nav_menu
$defaults = array(
'theme_location' => '',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
For adding the custom menu option that allows users to add and organize menus, you'll add this in your function.php
add_theme_support( 'menus' );
And then you can paste this code anywhere you want to display the custom menu
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>
the wp_nav_menu is the main function that displays menus on the WordPress page with a few arguments stored as an array. Sort_column instructs WordPress to follow the order in the options, and the container_class :.menu-header is the CSS class to style this menu. For displaying multiple menus, you can specify the id, slug, menu name with $id, $slug, $menu
I'm working on a new wordpress site and I'm building it with the Foundation framework. I'd like to add the class "main" to the links in the navigation that is built with wp_nav_menu. Eventually, I'll probably want to add the class "has-flyout" to others. Any idea on how to do this? I'm assuming I need to extend Walker (or can I do this with 'items_wrap'?), but that seems like overkill.
Currently, I have:
wp_nav_menu( array(
'theme_location' => 'primary_navigation',
'container' =>false,
'menu_class' => '',
'echo' => true,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 0,
'items_wrap' => '<ul class="nav-bar">%3$s</ul>'
));
You could use:
wp_nav_menu( array(
...
'menu_class' => 'main-menu',
...
And in your CSS (if that is what you want) access it like so:
ul.main-menu li { background: white; }
To add your "flyout" list-items maybe you could look into superfish? That system automatically adds "sf-with-ul" classes to list-items containing dropdowns.