admin管理员组文章数量:1130349
I have some problems to asign a class to tag with wp_nav_menu() instead of asign the class to the tag it creates a and asign the class to that one.
My register_nav_menu function:
function register_primary_menu() {
register_nav_menu('primary-menu', __('Primary Menu'));
}
add_action('init', 'register_primary_menu');
wp_nav_menu:
<?php
$defaults = array(
'theme_location' => 'primary-menu',
'menu' => '',
'container' => 'flase',
'container_class' => '',
'container_id' => '',
'menu_class' => 'nav navbar-nav',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '<li>',
'after' => '</li>',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
?>
What I want is this:
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
And what I get is this:
<div class="nav navbar-nav">
<ul>
<li class="page_item page-item-56"><a href="[URL]">Page 1</a></li>
<li class="page_item page-item-58"><a href="[URL]">Page 2</a></li>
<li class="page_item page-item-60"><a href="[URL]">Page 3</a></li>
<li class="page_item page-item-2"><a href="[URL]">Sample Page</a></li>
</ul>
</div>
I have some problems to asign a class to tag with wp_nav_menu() instead of asign the class to the tag it creates a and asign the class to that one.
My register_nav_menu function:
function register_primary_menu() {
register_nav_menu('primary-menu', __('Primary Menu'));
}
add_action('init', 'register_primary_menu');
wp_nav_menu:
<?php
$defaults = array(
'theme_location' => 'primary-menu',
'menu' => '',
'container' => 'flase',
'container_class' => '',
'container_id' => '',
'menu_class' => 'nav navbar-nav',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '<li>',
'after' => '</li>',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
?>
What I want is this:
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
And what I get is this:
<div class="nav navbar-nav">
<ul>
<li class="page_item page-item-56"><a href="[URL]">Page 1</a></li>
<li class="page_item page-item-58"><a href="[URL]">Page 2</a></li>
<li class="page_item page-item-60"><a href="[URL]">Page 3</a></li>
<li class="page_item page-item-2"><a href="[URL]">Sample Page</a></li>
</ul>
</div>
Share
Improve this question
asked Aug 20, 2015 at 8:29
AlexAlex
3757 silver badges18 bronze badges
2
|
3 Answers
Reset to default -2Make sure your menu does setup correctly in that location in Appearance / Menus, unless it wont display that class. After you set the theme location to Primary Menu, it should work fine. No idea why, guess its a bug in WordPress.
Also fix the typo: 'container' => false
You need to set 'container' => 'ul'.
I have same problem and i fix it. My theme_location i set primary in the functions.php file, but i don't set that location in the wp admin -> Appearance and in the Menu Settings set your location.
I have some problems to asign a class to tag with wp_nav_menu() instead of asign the class to the tag it creates a and asign the class to that one.
My register_nav_menu function:
function register_primary_menu() {
register_nav_menu('primary-menu', __('Primary Menu'));
}
add_action('init', 'register_primary_menu');
wp_nav_menu:
<?php
$defaults = array(
'theme_location' => 'primary-menu',
'menu' => '',
'container' => 'flase',
'container_class' => '',
'container_id' => '',
'menu_class' => 'nav navbar-nav',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '<li>',
'after' => '</li>',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
?>
What I want is this:
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
And what I get is this:
<div class="nav navbar-nav">
<ul>
<li class="page_item page-item-56"><a href="[URL]">Page 1</a></li>
<li class="page_item page-item-58"><a href="[URL]">Page 2</a></li>
<li class="page_item page-item-60"><a href="[URL]">Page 3</a></li>
<li class="page_item page-item-2"><a href="[URL]">Sample Page</a></li>
</ul>
</div>
I have some problems to asign a class to tag with wp_nav_menu() instead of asign the class to the tag it creates a and asign the class to that one.
My register_nav_menu function:
function register_primary_menu() {
register_nav_menu('primary-menu', __('Primary Menu'));
}
add_action('init', 'register_primary_menu');
wp_nav_menu:
<?php
$defaults = array(
'theme_location' => 'primary-menu',
'menu' => '',
'container' => 'flase',
'container_class' => '',
'container_id' => '',
'menu_class' => 'nav navbar-nav',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '<li>',
'after' => '</li>',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
?>
What I want is this:
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
And what I get is this:
<div class="nav navbar-nav">
<ul>
<li class="page_item page-item-56"><a href="[URL]">Page 1</a></li>
<li class="page_item page-item-58"><a href="[URL]">Page 2</a></li>
<li class="page_item page-item-60"><a href="[URL]">Page 3</a></li>
<li class="page_item page-item-2"><a href="[URL]">Sample Page</a></li>
</ul>
</div>
Share
Improve this question
asked Aug 20, 2015 at 8:29
AlexAlex
3757 silver badges18 bronze badges
2
-
I noticed
'container'=> 'flase',here'flase'instead offalse, this must not be a cause, but check correcting it. – Domain Commented Aug 20, 2015 at 8:41 - Fixed that mispelling :) But my issue still remains :) – Alex Commented Aug 20, 2015 at 10:10
3 Answers
Reset to default -2Make sure your menu does setup correctly in that location in Appearance / Menus, unless it wont display that class. After you set the theme location to Primary Menu, it should work fine. No idea why, guess its a bug in WordPress.
Also fix the typo: 'container' => false
You need to set 'container' => 'ul'.
I have same problem and i fix it. My theme_location i set primary in the functions.php file, but i don't set that location in the wp admin -> Appearance and in the Menu Settings set your location.
本文标签: menusProblem to asign class to ltulgt with wpnavmenu()
版权声明:本文标题:menus - Problem to asign class to <ul> with wp_nav_menu() 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749192944a2330459.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


'container'=> 'flase',here'flase'instead offalse, this must not be a cause, but check correcting it. – Domain Commented Aug 20, 2015 at 8:41