• Resolved raykinsella

    (@raykinsella)


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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The specific answer depends on how your theme outputs the logo in the first place. If it takes advantage of WP core’s the_custom_logo(), you can use the ‘get_custom_logo’ filter to replace the usual home URL with whatever URL you decide upon based on the return from wp_get_current_user().

    The filter passes to your callback function the markup for the logo and its associated anchor link. Use string functions to replace the anchor’s href attribute with the desired URL, then return the modified markup.

    If your theme does not make use of the_custom_logo(), there may still be a filter or pluggable function you can make use of. If not, you can customize your theme’s header.php file by creating a child theme, copying the file over, then edit as you see fit. For guidance on theme specifics, please seek advice from the theme’s official support channel.

    Thread Starter raykinsella

    (@raykinsella)

    ok thank you for the guidance. Ill give it a try.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change homepage logo link based on user role’ is closed to new replies.