[Resolved] Change Logo URL Based on User's Role

Home Forums Support [Resolved] Change Logo URL Based on User's Role

Home Forums Support Change Logo URL Based on User's Role

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #492493
    Randy

    Hi!

    My site has two main user roles, “dealer” and “supplier”. I’d like to have the main logo url link to a specified page based on the current user’s role. For any role other than “dealer” or “supplier”, I’d like the logo to link to the default home page. I referenced this topic which got me part of the way there, but I’m wondering if the edits I made to the code are correct. Could you guys double check for me? Any help would be much appreciated! Thanks!

    add_filter( 'generate_logo_href','tu_add_custom_logo_href' );
    function tu_add_custom_logo_href( $url )
    {
        $user = wp_get_current_user();
        if ( in_array( 'dealer', (array) $user->roles ) ) {   
            return '/dealer-home';
        }
    
        $user = wp_get_current_user();
        if ( in_array( 'supplier', (array) $user->roles ) ) {   
            return '/supplier-home';
        }
    
        // All the other pages
        return $url;
    }
    GeneratePress 2.0.2
    GP Premium 1.5.6
    #492495
    Randy

    Sorry! I should have mentioned, I’d like these changes to apply to all instances of the logo (i.e. sticky desktop, sticky mobile, etc.) if possible. Thanks guys!

    #492690
    Tom
    Lead Developer
    Lead Developer

    Your code looks great to me. Is it not working?

    Let me know 🙂

    #492963
    Randy

    Haha! I suppose I was second guessing myself.

    Sure enough, everything is working properly. Thank you for an AMAZING theme and support!

    #493059
    Tom
    Lead Developer
    Lead Developer

    You’re very welcome! Thanks for using it 🙂

    #1957486
    carlos

    Hola,

    He estado leyendo esto porque me interesa, mi pregunta es:

    ¿Existe algun plugin para poder redireccionar el logo de la home segun el rol del usuario?

    Si no existe ningun plugin de rol de usuario, donde debo colocar el rol de usuario y la url del usuario en el siguiente codigo?

    add_filter( 'generate_logo_href','tu_add_custom_logo_href' );
    function tu_add_custom_logo_href( $url )
    {
        $user = wp_get_current_user();
        if ( in_array( 'dealer', (array) $user->roles ) ) {   
            return '/dealer-home';
        }
    
        $user = wp_get_current_user();
        if ( in_array( 'supplier', (array) $user->roles ) ) {   
            return '/supplier-home';
        }
    
        // All the other pages
        return $url;
    }

    Un saludo

    #1957920
    David
    Staff
    Customer Support

    Hi there,

    you set the User Role here:

    if ( in_array( 'dealer', (array) $user->roles ) ) {

    Change dealer to the role you want to change.

    And this line:

    return '/dealer-home';

    Edit this to change the relative URL.

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