Archived topic
Change the word of the secondary menu when logged
3 replies · Started by jal-mj on January 25, 2023
Hello,
I have a secondary menu only with one item on desktop. In tablet and mobile is in the same menu (primary).
When someone is on the website and still not logged the word shown in the menu is: "Access". I would like to know if I can change this word when the user is logged to "My Account".
Is that possible?
Thank you.
Hi there,
1. Add this PHP Snippet to your site:
function swap_menu_logged_in( $menu_item ) {
if ( isset( $menu_item->classes ) ) {
if ( in_array( 'custom-login', $menu_item->classes ) ) {
if ( is_user_logged_in() ) {
// menu item logged in text
$menu_item->title = 'My Account';
} else {
// menu item logged out text
$menu_item->title = 'Access';
}
}
}
return $menu_item;
}
add_filter( 'wp_setup_nav_menu_item', 'swap_menu_logged_in' );
2. Go to Appearance > Menus
2.1 enable CSS Classes:
https://docs.generatepress.com/article/using-the-wordpress-menu-builder/#custom-classes
2.2 edit the menu item you want to change, and in the CSS classes field add: custom-login
This doc explains how to add PHP:
https://docs.generatepress.com/article/adding-php/
Magic.
Thank you very much David.
You're welcome