0

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 ( 
        is_user_logged_in() 
        && 'post' === $item->object
        && 'post_type' === $item->type
        # && … whatever you need to check for your invalidation of an item
    )
        $item->_invalid = TRUE;

    return $item;
} );

1 Answer 1

1

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

https://developer.wordpress.org/reference/hooks/wp_nav_menu_menu-slug_items/

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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