I want to use the below code from an answer of @kaiser, but I don't understand how to use it in a real situation. An example here would be appreciated.

BTW, I don't see many Q&A about the wp_setup_nav_menu filter.

add_filter( 'wp_setup_nav_menu', function( \stdClass $item ) {
    # Check conditionals, and invalidate an item in case
    if ( 
        && 'post' === $item->object
        && 'post_type' === $item->type
        # && … whatever you need to check for your invalidation of an item
        $item->_invalid = TRUE;

    return $item;
} );

Pls use filter wp_nav_menu_{$menu->slug}_items for conditionally adding or removing the menu-items.


See Method 2 at: https://wordpress.stackexchange.com/a/31753/116231

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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