Redirect non-admin after login, and in url - /admin

How and where, can i make function, that will redirect user (if it's not admin) to my specific URL? (the same - when logged user type /wp-admin URL.)

Topic wp-login-form user-access user-roles admin Wordpress

Category Web


All functions place in functions.php of your theme. And create redirect on template_redirect hook.

add_action('template_redirect', 'make_redirect');
function make_redirect() {
    if ( ! is_admin() && ! current_user_can( 'administrator' ) ) {
        wp_redirect( 'https://google.com' );
    }
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.