Send subscribers to the home page after login
Users who can’t write posts (subscribers, customers) land on the home page after logging in, instead of an almost empty dashboard.
<?php
add_filter(
'login_redirect',
static function ( $redirect_to, $requested, $user ) {
// Only the default destination; a link to a specific page is kept.
if ( $user instanceof WP_User && ! $user->has_cap( 'edit_posts' ) && ( '' === $requested || admin_url() === $requested ) ) {
return home_url( '/' );
}
return $redirect_to;
},
10,
3
);
In these packs
- Admin and login: Your branding on the login page, a tidier admin, and handy extras such as duplicating posts.