[Resolved] Change the word of the secondary menu when logged

Home Forums Support [Resolved] Change the word of the secondary menu when logged

Home Forums Support Change the word of the secondary menu when logged

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2508280
    jal-mj

    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.

    #2508351
    David
    Staff
    Customer Support

    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/

    #2508368
    jal-mj

    Magic.

    Thank you very much David.

    #2508440
    David
    Staff
    Customer Support

    You’re welcome

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.