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

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();
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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