Home / functions.php / Add the date to a specific wp_nav_menu
  • How to Add the date to a specific wp_nav_menu


    Adding this snippet to the functions.php of your wordpress theme will insert the date into your wordpress wp_nav_menu(). Don’t forget to change MENU_NAME to the name of the menu you wish to add the date.

    ( click code to copy )

    wordpress snippet : PHP

    add_filter('wp_nav_menu_items','add_date', 10, 2);
    function add_date($items, $args) {
        if( $args->theme_location == 'MENU_NAME' )
            return $items . '<li class="navdate">' . date("l F jS, Y") . '</li>';
        return $items;

    ( WordPress codex functions, hooks, in this snippet. )

    add_filter, wp_nav_menu, _n, wp,
  • Anonymous

    Where and how could one make use of such function?

    • If you notice at the top of my site, I have the last update date displayed. You could use it for something like this or in fact you could use this snippet to insert anything into the wp_nav_menu, eg: number of twitter followers, or facebook fans, or a select menu and search field etc. really anything that you need to insert into the menu when you need more then just a link.

      • Anonymous

        I’ll save it then. It might be handy for sometime in the future :)

        • or just visit wpsnipp in the future since I have it saved :) don’t forget to follow us on twitter or facebook.

  • Anton

    i use this technique to add a logout button to the nav if a user is logged in.

  • Max

    strange, the conditional seems to return false even if the menu name matches 

  • Should be added that the MENU_NAME is the one which the menu was registered with in functions.php not the one you set up in Admin.