I want to add text here within the anchor tag of the wordpress menu. So the menu structure would be
<ul>
<li><a href="#">Item1<br>
<span class="sub-text">text here<span></a>
</ul>
The "Item1" and "text here" will be dynamic. That is it can be edited from the wordpress back end.
I am using the wordpress function wp_nav_menu to show the menu. Below is the code.
$defaults = array(
'theme_location' => 'primary',
'menu' => '',
'container' => false,
'container_class' => '',
'container_id' => '',
'menu_class' => 'nav navbar-nav',
'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' => -1,
'walker' => ''
);
wp_nav_menu( $defaults );
Please help.
You need a custom Walker to achieve that:
$walker = new Menu_With_Description;
wp_nav_menu( array(
'theme_location' => 'primary',
'walker' => $walker
) );
Tutorials all over the place on the web, e.g.: http://www.wpbeginner.com/wp-themes/how-to-add-menu-descriptions-in-your-wordpress-themes/
Related
I have built WP templates before but I used to build them from scratch and I didn't have any issues like this. This time I decided to use html5blank boilerplate. Now I have this issue in the wp_nav_menu() where WordPress overrides the attributes I try to add in the items_wrap:
wp_nav_menu(
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 class="nav navbar-nav">%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
The WordPress docs state that the items_wrap should be assigned properly as <ul id="%1$s" class="%2$s">%3$s</ul>. There's also this filter function below that should supposedly replace the string values but there are no docs that I could find whatsoever that show an example of how do I approach it.
function my_wp_nav_menu_args($args = '')
{
$args['container'] = false;
return $args;
}
Don't know if I got it right – do you want the ul element contain the classes "nav" and "navbar-nav"? Then you only need to change "menu_class" within your array:
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'menu_class' => 'nav navbar-nav'
)
);
I solved this by removing item_wrap completely from the array and assigning in the menu_class .
I am new on WordPress and i don't know how to add any class in wp_nav_menu so if anybody who help me .
<?php wp_nav_menu(array('theme_location' => 'primary',
'menu'=>'Menu','container'=>'','items_wrap'=>'<ul class="nav navbar-nav">%3$s</ul>')); ?>
this may help. in wp-includes/nav-menu-template.php there is a function wp_nav_menu( $args = array() ) where the menu is creted. In the functions there is the $deafults array which loock like this:
$defaults = array(
'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' => '',
'theme_location' => '' );
change 'menu_class' => 'menu' to 'menu_class' => 'menu my_class'
anybody knows the blank theme html5 for wordpress? well i'm using this theme and i'm trying to add some style to the current page but i don't know how.
this is the function that the theme has:
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' => ''
)
);
}
thank you very much!
See your question is not clear enough!! The above code is for styling the nav menus,
Here you can change the menu class, the container and lot more!!
While customizing the wordpress menu I am having serious issues.
$setup = array( 'menu' => '', 'container' => 'div', 'container_class' => 'menu', 'container_id' => 'menu', 'menu_class' => 'menu', 'menu_id' => 'menu',
'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s">%3$s</ul>',
'depth' => 0, 'walker' => '', 'theme_location' => '','theme_location' => 'primary' );
wp_nav_menu($setup);
The issue:
You can see in the code that I have setted the menu_id as "menu". OR 'menu_id' => 'menu'
But it is not applying, only the menu_class is applying the id is not for the menu container. But why???? Please help me
If you are trying to apply css styles check if there is !important keyword in front of any style property.
I am trying to add a variable inside wp_nav_menu, I am not sure how to do it, please help me! Here is a snippet of the code:
wp_nav_menu(array(
'menu' => 'Main Menu',
'theme_location' => 'Main Menu',
'container' => null,
'container_class' => '',
'menu_id' => 'header-menu',
'menu_class' => '',
'before' => '<span class="text1">',
'after' => '</span><span class="text2">' . the_title($post->ID) . '</span>',
));
PLEASE HELP ME!
Is this what you mean? You may have to explain a little further, but this is how you'd add some additional values to wp_nav_menu.
wp_nav_menu(array(
'MyItem' => 'My Value', // <--new item
'MyotherItem' => 'My Other Value', // <--other new item
'menu' => 'Main Menu',
'theme_location' => 'Main Menu',
'container' => null,
'container_class' => '',
'menu_id' => 'header-menu',
'menu_class' => '',
'before' => '<span class="text1">',
'after' => '</span><span class="text2">' . the_title($post->ID) . '</span>',
));
Have a look at this tutorial. It's quite likely to answer your question and more
Try this this will add URL
wp_nav_menu( array( 'theme_location' => 'header-menu','menu_class' => 'drop', 'container' => 'nav', 'link_before' => '<span></span>') );
If you want it this way url
wp_nav_menu( array( 'theme_location' => 'header-menu','menu_class' => 'drop', 'container' => 'nav', 'link_before' => '<span>', 'link_after' => '</span>') );