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>

...but of course this will disappear on an update. What hook do I need to achieve the same?

  • 1
    After the container, or after the nav menu but inside the container? Sep 23, 2015 at 12:15
  • @TheDeadMedic After the nav but inside the container. Sep 23, 2015 at 12:56

2 Answers 2


Solved 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>
    <?php wp_nav_menu(array('container'=>false) ?>

You can also hook the items of the menu:


 * 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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.