N
N
NowebNolife2020-07-27 22:24:25
WordPress
NowebNolife, 2020-07-27 22:24:25

How to redirect authorized Wordpress users?

Good day!

Everything is very trivial.

When visiting the site, non-registered users (of course) get to the main page.
Authorized users enter their personal account, but cannot return to the main page; because explicit redirect specified:

function homepage_redirect()
{
    if ( is_front_page() && is_user_logged_in() ) {
        wp_redirect( home_url( '/welcome_back' ) );
        die;
    }
}
add_action( 'template_redirect', 'homepage_redirect' );


Requires that when first accessing the site , already logged in users are redirected to the /welcome_back page , but also have the opportunity to return to the main page.

I looked at the options on wp-kama, but somehow I did not find a suitable option...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly Kulikov, 2020-07-28
@NowebNolife

You can set a cookie like 'welcome=true' for the login and, if available, address it to your personal account. If you need to return to the main page - rewrite to 'false' and redirect

M
Maksym Davydchuk, 2020-07-27
@maksym1991

function admin_default_page() {
  return '/welcome_back';
}

add_filter('login_redirect', 'admin_default_page');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question