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.

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;

Comments  Leave a Reply

  1. 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.

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

    1. Ill take a look,

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

    1. Ahh cool that is a good way to add it. Good call,
      you should contribute a snippet or two http://wpsnipp.com/index.php/contribute/

  4. Where and how could one make use of such function?

    1. 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.

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

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

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!