Tagged: alternative menu, menu
Hi Guys,
I’d like to present an alternative Main Menu to users who are logged in. Is there a way of doing this using functions.php (I’m running a child theme)
website is over at http://www.onyoursoapbox.com
I did find this on the WordPress Forum but it didnt work:
// THIS THEME USES wp_nav_menu() IN ONE LOCATION FOR CUSTOM MENU.
if ( function_exists( ‘register_nav_menus’ ) ) {
$args = array(
‘menu’ => __( ‘Logged In Menu’ ),
‘visitor’ => __( ‘Visitor Menu’, )
);
register_nav_menus( $args );
}
Obviously I changed the variables to my menu names…
Stuart
ok – manage to resolve this – found a post elsewhere in your forum. I added the following code to functions.php
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() && $args['theme_location'] == 'avia' ) {
$args['menu'] = 'Main-Menu-logged-in';
} else {
$args['menu'] = 'Main-Menu-logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );