-
-
Save angeliquejw/7034866 to your computer and use it in GitHub Desktop.
WP menus that switch based on if user is logged in or not
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
/** | |
* Register menus in functions.php | |
*/ | |
register_nav_menus( array( | |
'logged-in' => __( 'Logged-in Menu Area', 'yourtheme' ), | |
'visitor' => __( 'Visitor Menu Area', 'yourtheme' ), | |
)); | |
/** | |
* Include in header.php or wherever you want to display menu | |
*/ | |
if (is_user_logged_in()){ | |
wp_nav_menu( array( | |
'menu' => 'Logged In Menu', | |
'container_class' => 'logged-in-menu', | |
'theme_location' => 'logged-in' | |
)); | |
} else { | |
wp_nav_menu( array( | |
'menu' => 'Visitor Menu', | |
'container_class' => 'visitor-menu', | |
'theme_location' => 'visitor' | |
)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment