Title: Functions.php specific redirection
Last modified: July 28, 2018

---

# Functions.php specific redirection

 *  [jujukp](https://wordpress.org/support/users/jujukp/)
 * (@jujukp)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/functions-php-specific-redirection/)
 * 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)

 *  [Jose Mortellaro](https://wordpress.org/support/users/giuse/)
 * (@giuse)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/functions-php-specific-redirection/#post-10535579)
 * 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
    -  This reply was modified 7 years, 10 months ago by [Jose Mortellaro](https://wordpress.org/support/users/giuse/).
    -  This reply was modified 7 years, 10 months ago by [Jose Mortellaro](https://wordpress.org/support/users/giuse/).
    -  This reply was modified 7 years, 10 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).

Viewing 1 replies (of 1 total)

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Jose Mortellaro](https://wordpress.org/support/users/giuse/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/functions-php-specific-redirection/#post-10535579)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
