WordPress: Redirect Users After Log In

First, the code…

// Redirect admins to the dashboard and other users elsewhere
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
function my_login_redirect( $redirect_to, $request, $user ) {
	// Is there a user?
	if ( is_array( $user->roles ) ) {
		// Is it an administrator?
		if ( in_array( 'administrator', $user->roles ) )
			return home_url( '/wp-admin/' );
		else
			return home_url();
			// return get_permalink( 83 );
	}
}

Then, some explanation…

For more information on this filter, read up on the login redirect filter.

In short, this function sends administrators to the WordPress Dashboard after log in and everyone else to the homepage of the site. To send everyone else to a specific page on your site, replace the id ’83′ to the id of the page. Don’t forget to comment and uncomment the necessary lines.

JoshStauffer.com runs on the Genesis Framework

Genesis Framework

Genesis empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go. It's that simple - start using Genesis now!

Take advantage of the 6 default layout options, comprehensive SEO settings, rock-solid security, flexible theme options, cool custom widgets, custom design hooks, and a huge selection of child themes ("skins") that make your site look the way you want it to. With automatic theme updates and world-class support included, Genesis is the smart choice for your WordPress website or blog.

Become a StudioPress affiliate

Speak Your Mind

*