0

I want to be able to change the WordPress default logo url (not the logo image) based on the user role. The image/logo will remain the same, only the url will change. Any assistance or ideas will be greatly appreciated.

  • the logo code has a filter at the end to filter the generated $html; developer.wordpress.org/reference/functions/get_custom_logo - what roles are you trying to check, and whereto are you trying to link them? – Michael Feb 29 at 4:13
  • I'm trying to check for 3 custom roles (cc1, cc2, cc3) and change the default WP logo url to their respective landing pages (specific url's). – Jimmy Feb 29 at 16:09
0

It depends on your theme. Typically themes set the logo href dynamically to the home_url() function or site_url() function.

Any good theme will provide you a filter hook to amend this destination using add_filter, which would return a new url. e.g.

function change_logo_url ($url) {
  $url = "www.changeurlhere.com";
  return $url;
}

add_filter('your_themes_hook', 'change_logo_url');
| improve this answer | |
0

Check out a few tips for your different options here
https://developer.wordpress.org/reference/functions/current_user_can/

If the current user is an administrator or editor

https://stackoverflow.com/questions/13404284/wordpress-capabilities-and-current-user-can-in-functions-php#13404440

// example
if (current_user_can( 'edit_posts' )) {
// serve a URL for this kind of user
}

| improve this answer | |
0

try this filter for the logo url link; adapt your landing page links:

function user_defined_logo_url( $html ) {
$cur_user = wp_get_current_user();
$user_role = $cur_user->roles[0];
$logo_url = esc_url( home_url( '/' ) );
switch( $user_role ) {
case "cc1":
        $switch_logo_url = esc_url( home_url( '/' ) . 'landingcc1' );   
    break;
case "cc2":
        $switch_logo_url = esc_url( home_url( '/' ) . 'landingcc2' );   
    break;
case "cc3":
        $switch_logo_url = esc_url( home_url( '/' ) . 'landingcc3' );   
    break;
default:
        $switch_logo_url = '';  
}
if( $switch_logo_url ) $html = str_replace( 'href="'.$logo_url, 'href="'.$switch_logo_url, $html );
return $html;
}
add_filter( 'get_custom_logo', 'user_defined_logo_url' );`
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.