Skip to content

Instantly share code, notes, and snippets.

@lloc
Last active November 19, 2015 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloc/fd8a2cdb0c23a1ce933f to your computer and use it in GitHub Desktop.
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
<?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