admin管理员组

文章数量:1328015

I would like to change the /wp-admin/index.php default page to something like /wp-admin/edit.php?post_type=page so that when a user logs in, they get redirected to /wp-admin/edit.php?post_type=page instead of /wp-admin/index.php. I will appreciate guides on this

I would like to change the /wp-admin/index.php default page to something like /wp-admin/edit.php?post_type=page so that when a user logs in, they get redirected to /wp-admin/edit.php?post_type=page instead of /wp-admin/index.php. I will appreciate guides on this

Share Improve this question asked Jul 21, 2020 at 5:51 bendict mutuabendict mutua 213 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

There's a filter called login_redirect where you can change the URL users get redirected to after logging in.

There's a nice example in the comments of the documentation page here: https://developer.wordpress/reference/hooks/login_redirect/

Here's a suggestion of how you could modify it to do what you want:

function wpdocs_my_login_redirect( $url, $request, $user ) {
    if ( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
        if ( $user->has_cap( 'administrator' ) ) {
            $url = home_url('/YOUR/CUSTOM/URL/HERE');
        } 
    }
    return $url;
}

add_filter( 'login_redirect', 'wpdocs_my_login_redirect', 10, 3 );

Note this code untested, let me know if you try it and have problems.

本文标签: Change wordpress admin home page