Advertisement
phpface

Redirect user to dashboard after logged in

Sep 26th, 2022
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. /**
  2.  * Redirect user to dashboard after logged in
  3.  */
  4. add_filter( 'login_redirect', function( $redirect_to, $requested_redirect_to, $user ){
  5.  
  6.     if( ! is_wp_error( $user ) && $user instanceof WP_User ){
  7.  
  8.         $user_url = get_author_posts_url( $user->ID );
  9.  
  10.         if( get_option( 'permalink_structure' ) ){
  11.             return trailingslashit( $user_url ) . 'dashboard'; 
  12.         }
  13.  
  14.         return add_query_arg( array(
  15.             'dashboard' =>  '1'
  16.         ), $user_url );
  17.     }
  18.     return $redirect_to;
  19. }, 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement