• Hello,

    I’m trying to create a function which redirect users logged in with a specific role when they click on my logo which usually drive to my homepage.

    Here is my code (I’m a rookie):

    /* test */
    function employeur_home() {
    if (in_array('employer', $GLOBALS['current_user']->roles) && is_front_page() ) {
    wp_redirect( get_permalink( 1166 ));
    exit();
    }
    }
    add_action('init', 'employeur_home');

    => I want employers to be redirected on my page ID 1166 instead of the homepage when they click on my logo.

    It doesn’t work. They can still go to my homepage.

    Can you help me ?

    Thanks a lot.

Viewing 1 replies (of 1 total)
  • I would try another method, maybe you could add a body class in according to the user role:

    function my_body_class( $classes ) {
    	foreach( $GLOBALS['current_user']->roles as $role ){
    		$classes[] = $role;
    	}
            return $classes;
    }
    add_filter( 'body_class', 'my_body_class' );

    and then using javascript or jQuery you could change the url of the link

    jQuery(document).ready(function(){
    jQuery('.body_role_class .link_selector').on('click',function(){
         document.getElementById('link_id').href = newUrl
    };
    });

    just change the selectors and newUrl … with the right ones

    If you do it with PHP you have to redirect the user, this would require more time for the loading of the final page

Viewing 1 replies (of 1 total)

The topic ‘Functions.php specific redirection’ is closed to new replies.