A
A
Alexander Bazarov2022-03-19 10:55:28
phpstorm
Alexander Bazarov, 2022-03-19 10:55:28

How to redirect to a specific page by username?

Hello. I really need help. How to redirect by username after login?

It should look like this:
Login: andrey
Redirect site.ru/andrey

I.e. it should turn out that Andrey will see only his page. Pages for each user are planned to be typed manually, because. the tasks are different, but the login form will be the same.

As I understand it, it should work like: if logined Andrey then redirect to site.ru/andrey

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Pochepko, 2016-06-14
@DJZT

You have not specified this server as the default download server. At you below notice hangs.

A
Artem Zolin, 2022-03-19
@artzolin

If you need an event after user authorization, then it is called login_redirect, and to get a link to the author's archive page, you can use the functionget_author_posts_url()

function login_redirect( $redirect_to, $request, $user ){
  if ( !is_wp_error( $user ) ) {
    return get_author_posts_url( $user->ID, $user->user_login );
  } else {
    return $redirect_to;
  }
}
add_filter( 'login_redirect', 'login_redirect', 10, 3 );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question