0

I want to get the username of the logged in users in the URL of my wordpress site. Like if user: arvind is logged in, I want to get the url as 'www.wp.com/arvind' or 'www.wp.com?user=arvind'.

Is there any solution for that?

1 Answer 1

1

I think this will do what you are looking for.

add_action("template_redirect", 'template_redirect');
function template_redirect() {
 global $wp;    
     if(is_user_logged_in() && !isset($_GET['user'])){
    $current_user=  get_userdata(get_current_user_id());
    wp_redirect(add_query_arg(array('user'=>$current_user->user_login),home_url($wp->request)));
    die();
}
}
4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.