How to automatically redirect and load the MainWP dashboard after login

I tried several approaches and code snippets I found. I added them either to a snippet manager or to the custom PHP of the MainWP Custom Dashboard extension. I did not succeed yet.

All of those did not work for me - anyone knows what could be the reason for this?

function my_login_redirect($redirect_to, $request, $user) {
    return admin_url('index.php?page=mainwp_tab');
add_filter('login_redirect', 'my_login_redirect', 10, 3);

function admin_default_page() {
  return '/wp-admin/admin.php?page=mainwp_tab';

add_filter('login_redirect', 'admin_default_page');
function mainwp_redirect_after_login( $redirect_to, $request, $user ) {
    // Check if the user has the MainWP dashboard page as their default dashboard
    if ( $user->has_prop( 'default_dashboard' ) && $user->default_dashboard == 'mainwp' ) {
        // Redirect the user to the MainWP dashboard
        $redirect_to = admin_url( 'admin.php?page=mainwp_tab' );
    return $redirect_to;
add_filter( 'login_redirect', 'mainwp_redirect_after_login', 10, 3 );

Hey @markus998

We have a help document that explains in detail how to add this redirect: How to change the default page after logging into WordPress - MainWP Documentation

I just verified this method and it is working as expected.

1 Like

Does anyone know if this still works? Obviously I tried all of the approaches already. Hence, I am not sure if something is wrong on my site or if it just does not work anymore. I would wonder though, as the site has nothing else installed than MainWP and WPCodeBox

I found it … I forgot I had Branda plugin installed as well for the login screen. Somehow Branda interferes that is why the code did not work. So it seems I can just set redirects after login within Branda as well which works.

1 Like

I’m glad you’ve managed to find a solution, and thank you for updating us.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.