Archived topic
Can we display the menus conditionally?
6 replies · Started by Pete on August 31, 2015
How would we dig into the code to put a conditional thing around the menus?
This plugin may be helpful: https://wordpress.org/plugins/if-menu/
Never used it before, but it looks promising.
Not the menu items, but the whole menu itself! Whooa!
This one does the whole menu: https://wordpress.org/plugins/menu-swapper/
Here's a way to hide the main menu if the user isn't logged on:
1. In your child theme create a new file like "my-styles.css"
2. Add this css to that file:
nav.main-navigation {
display: none;
}
3. Add this function to your child theme functions.php file:
add_action( 'wp_enqueue_scripts', 'enqueue_my_styles');
function enqueue_my_styles() {
if ( !is_user_logged_in() ) {
wp_enqueue_style( 'my-style', get_stylesheet_directory_uri().'/my-styles.css' );
}
}
Thanks!
No problem, glad I could help :)
