How to remove menu items from your navigation

This week I built a website with member area. While working on this project I faced a problem: how do I remove menu items based on the user logged in or not. Here is my solution:

Add these lines to your active theme’s functions.php

I’m using the wp_get_nav_menu_items filter as you can see it. In my case I remove menu items if menu item has a certain url. But you can check other things like class, or title or menu item’s text. In this scenario I just removed the menu items. To prevent users to access remove items you must add these lines too:

The getProfileUrl, getLoginUrl, getRegistrationUrl functions are written by myself. These functions returns url-s based on settings of my theme.

Close Menu