One of our go-to plugins for quick and easy menu customization here at Barefoot is the If Menu plugin which enables us to select conditions based on which a menu item is visible or not. The plugin comes with an impressive amount of preset values to choose from and even provides the necessary hooks to add custom filtering capabilities – something we will put to good use within a minute.
The idea is that we will add a few lines of code to the functions.php
file of our theme:
[php]function bf_if_menu_custom( $conditions ) {
$conditions[] = array(
‘name’ => ‘user is NOT logged in’,
‘condition’ => function($item) {
return !is_user_logged_in();
}
);
return $conditions;
}
add_filter( ‘if_menu_conditions’, ‘bf_if_menu_custom’ );[/php]
Line 3 is where the name of the custom condition is given
Line 5 uses the built-in is_user_logged_in()
function to determine whether the user is logged in or not, however, we would like to know the opposite of this so the end result is negated
After adding the above and saving functions.php
your menu items should now look like this:
Ideal for switching between showing a Login and a Logout button within the Menu.