Different Menu for Logged in Users in the Main menu area

Modern, responsive, unique and elegant one-page WordPress theme to showcase your creativity
GK User
Fri Jan 23, 2015 12:43 pm
Hi there,

is there a way to switch a menu in the main menu area according to the user's status (logged-in or guests)? I want to show different menus for my logged-in users and found this hint in the WP-codex:
http://codex.wordpress.org/Function_Ref ... d-in_users
Could you please provide some help, how to implement this?!
Is the function.php the right place or should it be done as a separate plugin?
What is the name of the main menu theme location?

Many Thanks
L.
User avatar
Fresh Boarder

GK User
Fri Jan 23, 2015 12:58 pm
Hi again,

I tried to use a simple code like
Code: Select all
function my_wp_nav_menu_args( $args = ” ) {

if( is_user_logged_in() ) {
$args['menu'] = ‘logged_in_menu’;
} else {
$args['menu'] = ‘header_logout_menu’;
}
return $args;
}
add_filter( ‘wp_nav_menu_args’, ‘my_wp_nav_menu_args’ );

my all footer menus also get changed.pls provide me any solution

This code does the trick, but it also changes the footer menu. I would like to change only the main menu in the header.
Is that possible?

L.
User avatar
Fresh Boarder

GK User
Fri Jan 23, 2015 1:28 pm
Hi,

Yes, it's possible, first you have to create the second menu, to do that, please edit Creativity/gavern/config/menus.json file and add your new menu:
Code: Select all
{
      "main": true,
      "location": "frontpagemainmenu-guest",
      "name": "Main menu - Frontpage Guests",
      "description": "Main menu of the theme for frontpage and logged out users"
   },

Now you can add new menu with menu items in your Dashboard -> Appearacne -> Menus and assign it to the new location.

In this theme it may be complicated a little, because there's different menu for the frontpage and for other subpages.
Anyway try to replace this fragment from Creativity/layouts/header.php file:
Code: Select all
<?php gavern_menu('frontpagemainmenu', 'gk-main-menu', array('walker' => new GKMenuWalker())); ?>

with:

Code: Select all
<?php if ( is_user_logged_in() ) : ?>
               <?php gavern_menu('frontpagemainmenu', 'gk-main-menu', array('walker' => new GKMenuWalker())); ?>
            <?php else : ?>
               <?php gavern_menu('frontpagemainmenu-guest', 'gk-main-menu', array('walker' => new GKMenuWalker())); ?>
            <?php endif; ?>


The similar conditions you may add to the subpagemainmenu and mobile menus in the same file.
User avatar
Moderator

GK User
Fri Jan 23, 2015 2:03 pm
It works fine, thanks for your valuable help.
My concern now is that those changes made to the two template files might disappear and be overwritten during the next template update.
Is it possible to implement this solution as an option in the main development of the Creativity team?

Kind Regards,
L.
User avatar
Fresh Boarder

GK User
Fri Jan 23, 2015 2:35 pm
We'll consider it but i think that this theme will then have too much options connected with the Menus.
If you want to keep your changes after the update, please use Child themes:
https://www.gavick.com/documentation/wo ... ild-themes
and override your header.php file.
User avatar
Moderator


cron