A fresh mix of code snippets and tutorials

WordPress redirect logged in users

Nice WordPress snippet to redirect logged in users to any location. Also optionally redirect visitors who are not logged in to WordPress.

The following function will redirect logged in users to the WP Dashboard, while redirecting visitors who are not logged in to the home page. Both locations are customizable.

// redirect logged in users
function wpmix_login_redirect($redirect_to, $request, $user) {
	if (is_array($user->roles)) {
		if (in_array('administrator', $user->roles)) return home_url('/wp-admin/');
		else return home_url();
add_filter('login_redirect', 'wpmix_login_redirect', 10, 3);

To implement, add this function to your theme’s functions.php file. Be sure to change the two redirect locations to suit your needs. For example, instead of redirecting logged in users to the Dashboard, you may want to send them to a sales page. To do so, change this:


..to this:


To the user, it just happens by magic.

Related Posts

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress