By Gediminas

2012-03-04 16:23:51 8 Comments

So, I want to create different menus for people who are logged in or not.

I got a reply that i should use a function

if (is_user_logged_in()) {
      wp_name_menu(array('theme_location' => 'logged_user' ));
} else {
      wp_nav_menu(array('theme_location' => 'new_user' ));

So, if I get this right, I put this into functions.php which is located in my child theme (anywhere inside the file?), then I create another menu and where it is "logged_user" and "new_user" I enter the names of the menus?


@helgatheviking 2012-03-04 16:32:42

i just did this for a site i am working on. first i registered 2 menus in functions.php:


function kia_menus(){

    register_nav_menus( array('primary-menu' => __( 'Primary Menu for Logged In Users', 'kia_theme' ), 
            'primary-loggedout' => __( 'Primary Menu for Logged Out Visitors', 'kia_theme')

and then where i want the 1 menu to appear based on the user's status (probably in header.php but depends on your theme):

if( !is_user_logged_in() ){
    wp_nav_menu( array( 'theme_location' => 'primary-loggedout' ) );
} else {
    wp_nav_menu( array( 'theme_location' => 'primary-menu' ) );

@Gediminas 2012-03-04 16:39:21

so the first part goes to functions.php and the second one to the place where i want the menus to be? In the second part do I have to change theme_location to the location or just leave it like that? And in the first part where it is kia_theme I would have to enter my child themes name which would look like Corporate_theme? I'm sorry for these newbie questions but I have no experience in coding

@helgatheviking 2012-03-04 18:00:00

yes part 1 goes in functions.php and yes the 2nd part goes where you want to display the menu. the theme_location can be whatever, but it needs to match what you declared in register_nav_menus. kia_theme is my text domain for translation purposes. you can make it be anything and if you don't plan to make your theme translatable, you don't need it at all.

Related Questions

Sponsored Content

1 Answered Questions

4 Answered Questions

1 Answered Questions

1 Answered Questions

1 Answered Questions

[SOLVED] two different separate sections on the same site

1 Answered Questions

1 Answered Questions

[SOLVED] Wordpress Menu Exchange for Mobile Layout

1 Answered Questions

[SOLVED] Unregister Nav Menu with fallback?

1 Answered Questions

[SOLVED] Getting menu items like get_pages

  • 2012-08-14 05:58:15
  • Sam
  • 5143 View
  • 1 Score
  • 1 Answer
  • Tags:   menus walker

Sponsored Content