Shaniawan
Shaniawan

Reputation: 243

wp_redirect is not working on functions.php file

I have a scenario that if any user that is created manually by adding in wp_users table in database(In case of importing csv of users in db)and if that user visits my site then he will be redirected to welcome page. Forexample www.example.com is my site domain.If users visits this site then they will re-directed to www.example.com/welcome/ For this purpose i have used this following code in functions.php file.

function redirectUser(){
wp_redirect(home_url('/welcome/'));
exit;

}
add_action('init','redirectUser');

But when i refresh my home page,Page goes die.So what i am doing wrong.Any help would be appreciable

Upvotes: 2

Views: 1764

Answers (1)

user6887026
user6887026

Reputation:

run it code without add actions

wp_redirect(home_url('/welcome/'));

// OR

function redirectUser($url){
    wp_redirect(home_url($url));
    exit;
}

redirectUser(home_url('/welcome/'));

Upvotes: 1

Related Questions