WordPress Menus - markhowellsmead/helpers GitHub Wiki

Programmatically add an entry to a specific menu

add_filter('wp_nav_menu_MENU_SLUG_items', function ($items, $args) {
    return sprintf(
        '<li class="menu-item menu-item-type-custom menu-item-object-custom">%s</li>%s',
        'Hello world',
        $items
    );
}, 10, 2);

Mark (highlight) post type parent as active item in Wordpress Navigation.

Mark (highlight) post type parent as active item in Wordpress Navigation. When you visit a post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.

⚠️ **GitHub.com Fallback** ⚠️