admin管理员组文章数量:1313121
I know I can edit the items within the wp_nav_menu by declaring a custom walker, but I want to add some code just inside the container, which isn't handled by a walker.
It's in nav-menu-menu-template.php, so I can get the desired effect by adding my code after line 329...
$nav_menu .= "<div class='topper'>
<a href='".get_home_url()."' class='intranet'>H</a>
</div>";
...but of course this will disappear on an update. What hook do I need to achieve the same?
I know I can edit the items within the wp_nav_menu by declaring a custom walker, but I want to add some code just inside the container, which isn't handled by a walker.
It's in nav-menu-menu-template.php, so I can get the desired effect by adding my code after line 329...
$nav_menu .= "<div class='topper'>
<a href='".get_home_url()."' class='intranet'>H</a>
</div>";
...but of course this will disappear on an update. What hook do I need to achieve the same?
Share Improve this question edited Sep 23, 2015 at 12:57 SinisterBeard asked Sep 23, 2015 at 12:01 SinisterBeardSinisterBeard 1,2173 gold badges14 silver badges34 bronze badges 2- 1 After the container, or after the nav menu but inside the container? – TheDeadMedic Commented Sep 23, 2015 at 12:15
- @TheDeadMedic After the nav but inside the container. – SinisterBeard Commented Sep 23, 2015 at 12:56
2 Answers
Reset to default 1Solved it by setting container
to false
and then wrapping it manually.
<nav class="main_navigation">
<div class="topper">
<a href="<?=get_home_url()?>" class="intranet">H</a>
</div>
<?php wp_nav_menu(array('container'=>false) ?>
</nav>
You can also hook the items of the menu:
wp-includes/nav-menu-template.php
/**
* Filters the HTML list content for navigation menus.
*
* @since 3.0.0
*
* @see wp_nav_menu()
*
* @param string $items The HTML list content for the menu items.
* @param stdClass $args An object containing wp_nav_menu() arguments.
*/
$items = apply_filters( 'wp_nav_menu_items', $items, $args );
Example of adding a custom item on the begin of the nav:
function add_custom_item( $items, $args ) {
$custom_item = "<a href='".get_home_url()."' class='intranet'>H</a>";
return $custom_item . $items;
}
add_filter( 'wp_nav_menu_items', 'add_custom_item', 10, 2 );
本文标签: functionsHow do I hook into the container of wpnavmenu
版权声明:本文标题:functions - How do I hook into the container of wp_nav_menu? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741948202a2406552.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论