Wordpress Primary menu not updating after reordering menu items - wordpress

In functions.php, I registered primary menu like this-
<?php
register_nav_menus( array(
'menu-1' => esc_html__( 'Primary', 'intralink' ),
) );
?>
And in Homepage I have used below code:
<?php
wp_nav_menu( array(
'theme_location' => 'Primary',
'container' => 'ul',
'container_class' => 'navbar-collapse collapse',
'menu_class' => 'nav navbar-nav navbar-right'
));
?>
Then after creating a menu from wordpress Menus, nothing happens? Maybe it's not drag drop problem, maybe it's something I did wrong.
Thanks

Theme location should be 'menu-1'
It should look like the following
wp_nav_menu( array(
'theme_location' => 'menu-1',
'container' => 'ul',
'container_class' => 'navbar-collapse collapse',
'menu_class' => 'nav navbar-nav navbar-right'
));
Hope this will solve your issue.

Related

Removing WordPress Wrapper Div When container => false Fails

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'
));

Wordpress wp nav menu doesn't work

I don't understand why it's impossible for me to get my custom menu on my front-end page
I use:
<?php
wp_nav_menu( array(
'theme_location' => 'jdsMainMenu',
'depth' => '1',
'menu_class' => 'jds-main-menu-list',
'menu_id' => 'jds-nav',
'container' => '',
'items_wrap' => '<ul class="jds-main-menu-list">%3$s</ul>'
));
?>
I have my menu in WordPress back office.
I try to make:
var_dump(get_registered_nav_menus());
My menu is available: but nothing display with wp_nav_menu...
Maybe some one have an idea...
I am sure you are using correct ID for theme location
screenshot
function register_my_menus() { register_nav_menus(
array(
'jdsMainMenu' => __( 'Navigation Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
wp_nav_menu( array(
'theme_location' => 'jdsMainMenu',
'depth' => '1',
'menu_class' => 'jds-main-menu-list',
'menu_id' => 'jds-nav',
'container' => '',
'items_wrap' => '<ul class="jds-main-menu-list">%3$s</ul>'
));

Adding class to menu_class to wp_nav_menu adds class to div instead of ul

I am very new to wordpress themeing . I am trying to create a Twitter Bootstrap menu to my newly created theme as below in header.php page.
$defaults = array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => '',
'container_class' => '',
'container_id' => '',
'menu_class' => 'navbar-collapse collapse',
'menu_id' => 'navbar',
'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 );
With the above codes, I am expecting to add a class to navbar-collapse collapse to ul, but instead it produces HTML as below :
<div class="navbar-collapse collapse"><ul><li class="page_item page-item-11"> etc. How can I add class ul ?
Check you've actually registered 'header-menu' via register_nav_menus.
Removing theme_location => 'header-menu' will resolve the issue until you've registered your navigation ID correctly.
You should have this in your functions.php
register_nav_menus( array(
'header-menu' => __( 'Header Menu', 'domain' ),
) );
Try checking out a function that's already been made like this one. It will create the correct syntax for the menu to work.
Due to the fact that no one solved your problem. I want to provide a solution for future users. The solution is in the container parameter of the wp_nav_menu function.
Documentation:
https://developer.wordpress.org/reference/functions/wp_nav_menu/
container string - Whether to wrap the ul, and what to wrap it with.
Default 'div'.
To make parameter menu_class add it`s valuse to correct element, in your case it is ul element, you have to define container parameter as div, like below. Then parameter container_class will have default class 'menu-{menu slug}-container' because it`s not have any value given. container_id parameter also will be empty becouse there is no value given.
$defaults = array(
'theme_location' => 'header-menu',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_id' => 'navbar',
'menu_class' => 'navbar-collapse collapse',
);
wp_nav_menu( $defaults );
Then menu_class and menu_id parameters will be added to the ul element and ul element will look this <ul id="navbar" class="navbar-collapse collapse">.
In case you don`t want to have div container delete container_class and container_id and leave container parameter with ul value like this:
'theme_location' => 'header-menu',
'container' => 'ul',
'menu_id' => 'navbar',
'menu_class' => 'navbar-collapse collapse',

How to convert yamm3 into wordpress

I am using bootstrap 3.2 in my wordpress project. I want to create a megamenu in bootstrap. I have found YAMM 3 has this functionality. But this is in HTML. Can any one tell me how can i integrate it in my wordpress project?
did you try use this nav walker?
https://github.com/macdonaldr93/yamm-nav-walker
so your code should look like this
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 4,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav yamm',
'fallback_cb' => 'Yamm_Nav_Walker_menu_fallback',
'walker' => new Yamm_Nav_Walker())
);
?>

Wordpress child theme, adding secondary menu

<?php
if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') ) {
wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );
} else {
?>
I'm trying to add a secondary menu from Wordpress menu management in my functions.php of my child theme for Woothemes Canvas.
I figure there's a way to add it to the array above but I can't get it to work. Thoughts?
Jason, you first need to register your 'new' (secondary) menu with register_nav_menu() like:
add_action( 'init', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'secondary-menu', __( 'Secondary Menu' ) );
}
You do this in your theme's functions.php file.
Then you're able to call that menu in your template files. To use your code above, you'll probably want something like:
if ( function_exists('has_nav_menu') && has_nav_menu('secondary-menu') ) {
wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) );
}
or maybe
if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') && has_nav_menu('secondary-menu') ) {
wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );
wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) );
}
The second one will output both menus if they both exist, the first one will probably be used in addition to the one you posted in your initial question.
But in my case, I did not use the init action, just put the menu register function in my child theme's function.php file
register_nav_menu( 'footer', 'Footer Menu' );

Resources