How to make two header menu


#1

Hi,

I want two header menu bar for logged in user and logged out user. Could you please let me know how can I do it?


#2

Hello there,

Thank you for getting in touch. I though that it requires writing some extra codes to achieve that objective. I’d recommend you to do it in child theme mode. Download the Sydney child theme here.

  1. You should need to register two custom menu locations in the child theme’s functions.php file.
register_nav_menus( array(
	'logged_in_menu' => __('Logged in Menu', 'sydney-child'),
	'logged_out_menu' => __('Logged out Menu', 'sydney-child),
) );
  1. Place your newly created menu location in the header section. Copy header.php file of parent theme to child theme folder. So you should have sydney-child/header.php. Use is_user_logged_in() conditional to check which one should be displayed for logged in user.
<?php 

if( is_user_logged_in() ) {

	// Displayed for logged in user
	wp_nav_menu( array( 'theme_location' => 'logged_in_menu', 'fallback_cb' => 'sydney_menu_fallback' ) ); 
	
} else {

	// Displayed for logged out user
	wp_nav_menu( array( 'theme_location' => 'logged_out_menu', 'fallback_cb' => 'sydney_menu_fallback' ) );	
	
}	

?>
  1. Define the menu items for each location through Appearance > Menus

You might need to write some CSS code to style those menus.

I hope this reply helps.

Warmest regards,
Kharis


#3

Hello,

I am not expert either php nor css. However, firstly I copied full website content in my local computer so safety reason.

Steps I have done and the result came out.

  1. I went to Appearance>Editor>Select Sydney child theme> Then click on the Theme functions (functions.php).
  2. There were some predefined codes.

<?php
// Exit if accessed directly
if ( !defined( ‘ABSPATH’ ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( ‘chld_thm_cfg_parent_css’ ) ):
function chld_thm_cfg_parent_css() {
wp_enqueue_style( ‘chld_thm_cfg_parent’, trailingslashit( get_template_directory_uri() ) . ‘style.css’ );
}
endif;
add_action( ‘wp_enqueue_scripts’, ‘chld_thm_cfg_parent_css’ );

// END ENQUEUE PARENT ACTION

After these line I pasted the code which you gave:

register_nav_menus( array(
‘logged_in_menu’ => __(‘Logged in Menu’, ‘sydney-child’),
‘logged_out_menu’ => __(‘Logged out Menu’, 'sydney-child),
) );

Then Update file. After that I see only white page in back-end and even website front-end.
Could you please let me know steps by steps where these code should be posted and how.
Or any other alternatives to get help from you.

Thank you very much. I am looking forward to hearing from you.

On the other hand, I also copied header.php from sydney theme to child theme using ftp. And I installed child theme long ago worked with some css for customizing and everything was working fine. Now I just need to distinguish the two menu items for logged in user and logged out visitor.