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.
Related
Im having problems using the wp_nav_menu() function to get a defined menu and remove the ul and li default classes and replace with entirely custom classes. How can this be achieved?
I hope you're fine. If you look at the source of wp_nav_menu, you see the list of arguments that it accepts:
$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>',
'item_spacing' => 'preserve',
'depth' => 0,
'walker' => '',
'theme_location' => '',
);
Given the explanation you provided, i think 'items_wrap' will solve your problem.
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!!
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/
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>') );