I find I spend very little time on the WordPress dashboard. Additionally, the Dashboard can be confusing for users when all you want to do is write a blog post. Thanks to the power of WordPress filters, we can send users directly to the backend Posts screen on log in and skip the dashboard.
We accomplish this with the login_redirect
filter. By adding the following code snippet, we can redirect all logins to the backend Posts screen.
Example Redirect All Logins (Don’t Use this Code)
add_filter( 'login_redirect', 'fe_skip_dash' );
function fe_skip_dash( $url ) {
return admin_url( 'edit.php' );
}
How to Redirect Logins to Backend Posts Screen
The problem with the code above is we’ll redirect all logins to the backend Posts screen but some users may not have access to view that page (e.g. by default Subscribers can not view the backend posts screen and will get an error message).
You do not have sufficient permissions to access this page.
We can solve this problem by checking the user can view the page before we redirect them.
add_filter( 'login_redirect', 'fe_skip_dash', 10, 3 );
function fe_skip_dash( $url, $request, $user ) {
if ( ! $user || is_wp_error( $user ) ) {
// There is no user.
// Do not change the URL.
return $url;
}
if ( ! user_can( $user, 'edit_posts' ) ) {
// User can not view backend Posts screen.
// Do not change the URL.
return $url;
}
// Change the URL.
return admin_url( 'edit.php' );
}
WordPress Skip Dashboard Plugin
I’ve combined this code into a WordPress plugin available on GitHub, WordPress Skip Dashboard Plugin.
Leave a Reply