Archived topic
How to REPLACE the primary menu for logged in users
5 replies · Started by Wesley on November 28, 2022
Hi, I have a problem that I've tried for hours to resolve by reading different posts here, but I'm still at a loss.
For logged in users, I'm looking to complete replace the main header navigation.
Here is a video with more detail:
https://www.loom.com/share/6140e785087e48429f9607356dcb6c07
Hope you can help.
Thanks
Wesley
Hi there,
instead of hooking in the secondary navigation and dealing with a whole bunch of different HTML and Customizer settings as well as GP hooks, the simplest option maybe to swap the Menus using this PHP Snippet:
add_filter( 'wp_nav_menu_args', function ( $args ) {
if ( 'primary' === $args['theme_location'] ) {
if ( is_user_logged_in() ) {
$args['menu'] = 'LOGGED IN';
} else {
$args['menu'] = 'LOGGED OUT';
}
}
return $args;
} );
Sorry if this is a dumb question, David.
Can you clarify where I place that PHP snippet?
Thanks,
Wesley
Sorry - i should have provided this doc, which explains:
https://docs.generatepress.com/article/adding-php/
TLDR:
Are you using a Child Theme?
If Yes, then you can add the snippet to your child theme functions.php file
If No, then use the Code Snippets plugin ( link in the above doc ) and add it to a New Snippet.
Awesome. It works.
I'm eternally grateful, David.
Have a great week.
Wesley
Glad to be of help!