Site logo

Archived topic

Can we display the menus conditionally?

6 replies · Started by Pete on August 31, 2015

Viewing posts 1–7 of 7

How would we dig into the code to put a conditional thing around the menus?

Not the menu items, but the whole menu itself! Whooa!

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 :)

This archived topic is closed to new replies.