Skip to content

Instantly share code, notes, and snippets.

@gmaggio
Created July 4, 2014 23:15
Show Gist options
  • Save gmaggio/8f74eeed29e414688b60 to your computer and use it in GitHub Desktop.
Save gmaggio/8f74eeed29e414688b60 to your computer and use it in GitHub Desktop.
[Wordpress] Redirect Non-Admin Users to Homepage After Login ( http://tommcfarlin.com/redirect-non-admin/ )
<?php
/**
* Redirect non-admins to the homepage after logging into the site.
*
*/
function my_login_redirect ( $redirect_to, $request, $user ) {
return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url();
} // end my_login_redirect
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
// Source: http://tommcfarlin.com/redirect-non-admin/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment