Home / calendar / Insert calendar into wp_nav_menu
  • How to Insert calendar into wp_nav_menu

    insert-calendar-into-wp_nav_menu

    Needed this for a recent project as a client wanted to display the wordpress calendar as a dropdown item within the menu. Add this snippet to the functions.php of your wordpress theme will add a new menu item to your wp_nav_menu that has a submenu calendar.

    wordpress snippet : PHP

    <>
    add_filter('wp_nav_menu_items','add_calendar', 10, 2);
    function add_calendar($items, $args) {
        if( $args->theme_location == 'header-navigation' )
            return $items . '<li><a href="#">Calendar</a><ul class="sub-menu"><li>' . get_calendar(true,false) . '</li></ul></li>';
    }
    

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

    add_filter, wp_nav_menu, get_calendar, _n, wp,