wp_nav_menu not outputting as expected from configuration - wordpress

I've got a nav function in functions.php:
function html5blank_nav()
{
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => false,
'menu_class' => 'nav',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
}
And it's called in header.php with:
<?php html5blank_nav(); ?>
And my output is:
<div class="nav">
<ul>
<li class="page_item page-item-2">Sample Page</li>
<li class="page_item page-item-4">Test page</li>
</ul>
</div>
But What I was trying to achieve was this structure:
<ul class="nav">
<li>Sample Page</li>
<li>Test page</li>
</ul>
I thought that setting container=false would get rid of the containing divs, and that setting menu_class='nav' would add the nav class to the ul as it states here: http://codex.wordpress.org/Function_Reference/wp_nav_menu
Why isn't it recognising my settings?

from the Codex:
In order to remove navigation container, theme location specified in functions.php and used among arguments in function wp_nav_menu ( eg. 'theme_location' => 'primary-menu' ) must have a menu assigned to it in administration! Otherwise argument 'container' => 'false' is ignored

Related

wrapping parent and child pages in separate ul in wp nav menu

I need the nav menu structure like the following.
<ul class="side-menu-list">
<li>Parent Page 1
<ul>
<li>Traditional Braces</li>
<li>Lingual Braces</li>
<li>Invisalign</li>
<li>Temporary Anchorage Devices</li>
<li>Surgical Orthodontics</li>
<li>TMJ Treatment</li>
<li>All About Retainers</li>
<li>Emergency Treatment</li>
</ul>
</li>
</ul>
<ul class="side-menu-list">
<li>Paent Page 2
<ul>
<li>Early Treatment/Prevention</li>
<li>Two-Phase Treatment</li>
<li>Hometown Smiles Gallery</li>
</ul>
</li>
</ul>
Which means every parent page and its sub pages should be wrapped in a ul. So iam looking for a custom walker menu so that every main menu and its sub menus will be wrapped in a ul tag dynamically.
// Register two menus
// Go to Menus and add menu items to each menu
// call the wp_nav_menu function twice.
// this goes in functions.php
register_nav_menus( array(
'primary' => __( 'Primary', 'text-domain' ),
'secondary' => __( 'Secondary', 'text-domain' )
) );
<ul class="side-menu-list">
<li>Parent Page 1
// display the menu on front end
wp_nav_menu(
array(
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_id' => 'primary',
'container_class' => 'primary',
'menu_class' => 'ul-class' ) );
</li>
</ul>
<ul class="side-menu-list">
<li>Parent Page 1
wp_nav_menu(
array(
'theme_location' => 'secondary',
'depth' => 2,
'container' => 'div',
'container_id' => 'secondary',
'container_class' => 'secondary',
'menu_class' => 'ul-class' ) );
</li>
</ul>

Register Custom menu in wordpress

How to register this menu in wordpress dynamically ?
i'am having problem to dynamic menu in wordpress
<nav id="nav">
<ul>
<li>Division
<ul class="dropotron dropotron-level-0 center" style="-moz-user-select: none; position: absolute; z-index: 1000; left: 184.767px; top: 29px; opacity: 1; display: none;">
<li ><a style="display: block;" href="real-estate.html">Real Estate</a></li>
<li><a style="display: block;" href="waterpump.html">Water Pump</a></li>
<li ><a style="display: block;" href="fmcg.html">FMCG</a></li>
<li ><a style="display: block;" href="infrastructure.html">Infrastructure Project</a></li>
</ul>
</li>
<li >About Us</li>
<li class="break">Career</li>
<li >Contact Us</li>
</ul>
</nav>
Thanks
i'm not sure i'm fully understand what you'r meant when you say 'register this menu in wordpress dynamically', but if you meant to register custom menu and display it so follow this:
put this code on the 'functions.php' file: (if you are not using a theme of your own then create a child theme if you didn't already)
function register_your_menu() {
register_nav_menu('your-menu-location',__( 'Your Menu Description' ));
}
add_action( 'init', 'register_your_menu' );
*register your new menu - it will display the new menu on the admin panel so set it as you like.
put this code on the place you want the menu to appear on the theme and customize the '$defaults' settings as you like (you can find more info here: http://codex.wordpress.org/Function_Reference/wp_nav_menu):
if ( has_nav_menu( 'your-menu-location' ) ) {
$defaults = array(
'theme_location' => 'your-menu-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 );
}

wp_nav_menu() doesn't work poperly

I need to use custom items_wrap format but it seems like it doesn't work at all.
<?php wp_nav_menu( array(
'menu_class' => 'menu',
'menu' => 'mobile-menu',
'theme_location' => 'main-navigation',
'container' => false,
'items_wrap' => '<ul data-role="listview">%3$s</ul>' ) ); ?>
The OUTPUT
<div class="menu">
<ul>
<li class="page_item page-item-2">Sample Page</li>
</ul>
Problem is that in output <ul> doesn't have data-role assigned as it should have.
Anyone have an idea why this function doesn't get the parameter right?
You could try this code:
<ul class="menu">
<?php wp_nav_menu( array(
'menu' => 'mobile-menu',
'theme_location' => 'main-navigation',
'container' => false,
'items_wrap' => '%3$s' ) ); ?>
</ul>

how to set css and html structure in wp_nav_menu() function in wordpress

I have a HTML coded navigation menu which has CSS style and cool animation.
Now i wants to add this CSS and structure in Word Press. I have tried and also used in wp_nav_menu() .But result is so far. How could i use this CSS in Word Press.
CSS also included and working fine if i am using statically navigation HTML.
$defaults = array(
'theme_location' => 'header-menu',
'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 );
Wants to add this css in Wordpress navigation menu
<ul class="menu">
<li class="current-menu-parent">Home
<ul class="sub-menu">
<li class="current-menu-item">Background Color</li>
<li>Background Color With Fullwidth Slider</li>
<li>Clean Style</li>
<li>Clean Style With Fullwidth Slider</li>
<li>Background Image</li>
</ul>
</li>
<li>Pages
<ul class="sub-menu">
<li>About</li>
<li>Full Width</li>
<li>Gallery</li>
<li>404 Page</li>
<li>Sitemap</li>
</ul>
</li>
</ul>
Is not so dificult to do that. You need to declare the class of the menu in array.
here is an exemple:
<?php $defaults = array(
'theme_location' => '',
'menu' => 'TopMenu',
'container' => 'ul',
'container_class' => 'topmenu-{topmenu slug}-container',
'container_id' => 'topmenu',
'menu_class' => 'topmenu',
'menu_id' => 'topmenu-{topmenu slug}[-{increment}]',
'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' => ''
); ?>
<?php wp_nav_menu( $defaults ); ?>
In this "topmenu" is the css class. I believe that from here you will be able to customize your menu.
Hope it help's you!
If you need a css sample, just let me know!

style ul part in custom menu in wordpress

How to style ul part of navigation menu(custom menu) in wordpress? I have tried
<div id="serviceMenu">
<?php wp_nav_menu(array('menu'=>'navigation with more options',
'container' => '',
'menu_id' => '',
'menu_class' => 'menu')); ?>
</div>
But I don't know how to assign class="menu" to ul part?
Please help!!!
After reading the manual of wp_nav_menu I would suggest the following code for adding an menu class to the ul:
<div id="serviceMenu">
<?php
wp_nav_menu(array(
'menu'=>'navigation with more options',
'container' => '',
'menu_id' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'menu_class' => 'menu'));
?>
</div>
http://codex.wordpress.org/Function_Reference/wp_nav_menu

Resources