Send Non-Editors to the Homepage After Login
Users who cannot edit posts (subscribers, customers) land on the homepage after logging in instead of their admin profile. Staff still go to the dashboard.
Opens WPIDE on
Code
add_filter( 'login_redirect', function ( $redirect_to, $requested, $user ) {
if ( ! $user instanceof WP_User || user_can( $user, 'edit_posts' ) ) {
return $redirect_to;
}
// Respect explicit front-end destinations such as a "log in to comment" link.
if ( $requested && false === strpos( $requested, admin_url() ) ) {
return $redirect_to;
}
return home_url( '/' );
}, 10, 3 );
Notes
Replace home_url( '/' ) with any URL, for example home_url( '/account/' ).
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.