I want to redirect an user and his user ID is 6. So I added this code into my functions.php
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
if ($user_id == 6) {
/* redirect users to front page after login */
function redirect_to_front_page() {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl');
}
}
add_action('login_form', 'redirect_to_front_page');
}
}
But still the user goes to the rpofile page after the log-in. How can I get it works?
[update] Then I've tried to change to username instead of user ID but still same. He gets profile page after login. like this:
function redirect_to_front_page() {
global $redirect_to;
if ( is_user_logged_in() ) {
//$user_id = get_current_user_id();
$current_user = wp_get_current_user();
//if ($user_id == 6)
if ($current_user->user_login = 'hirer') {
/* redirect users to front page after login */
if (!isset($_GET['redirect_to'])) {
$redirect_to = get_option('siteurl');
}
}
}
}
add_action('login_redirect', 'redirect_to_front_page');
still nothing changed. The user gets profile page when he login.
login_form
) is wrong.www.mysite.com