Site logo

Archived topic

Change Logo URL Based on User's Role

6 replies · Started by Randy on February 9, 2018

Viewing posts 1–7 of 7

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;
}

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!

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

Let me know :)

Haha! I suppose I was second guessing myself.

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

You're very welcome! Thanks for using it :)

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

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.

This archived topic is closed to new replies.