Last active
November 19, 2015 21:24
-
-
Save lloc/fd8a2cdb0c23a1ce933f to your computer and use it in GitHub Desktop.
WordPress - How to show a nav menu_item only to users who are logged in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'wp_setup_nav_menu_item', function ( $menu_item ) { | |
if ( ! is_user_logged_in() && | |
in_array( 'private', $menu_item->classes ) | |
) { | |
$menu_item->_invalid = true; | |
} | |
return $menu_item; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment