Change homepage logo link based on user role
-
Hi
I have a php question which I am hoping to get some guidance with. I have two homepages depending on the role of a registered user, employer or employee. Once the user is logged in, and they happen to click the website logo, I want to send them the correct homepage based on their role.I am really struggling to get started with this in php (I have not been coding in this language for long). I know how to redirect my users to custom pages on login/registration (see code below from my functions.php). How do I activate the same code by clicking on the website logo?
Any help would be much appreciated!
Thanks
Ray
/* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
$role = $user->roles[0];
$postjob = home_url(‘/post-a-job/’);
$submitresume = home_url(‘/submit-resume/’);
if( $role == ’employer’ ) {
//Redirect administrators to the dashboard
$redirect = $postjob;
} elseif ( $role == ‘customer’ ) {
//Redirect shop managers to the dashboard
$redirect = $submitresume;
} elseif ( $role == ‘editor’ ) {
//Redirect editors to the dashboard
$redirect = $dashboard;
} elseif ( $role == ‘author’ ) {
//Redirect authors to the dashboard
$redirect = $dashboard;
} elseif ( $role == ‘subscriber’ ) {
//Redirect customers and subscribers to the “My Account” page
$redirect = $myaccount;
} else {
//Redirect any other role to the previous visited page or, if not available, to the home
$redirect = wp_get_referer() ? wp_get_referer() : home_url();
}
return $redirect;
}
add_filter( ‘woocommerce_login_redirect’, ‘wc_custom_user_redirect’, 10, 2 );// After registration, logout the user and redirect to login screen
function custom_registration_redirect() {
wp_logout();
}
add_action(‘woocommerce_registration_redirect’, ‘custom_registration_redirect’,12, 2);
- The topic ‘Change homepage logo link based on user role’ is closed to new replies.