Wordpress Developer

Ganesh Veer

Alandi Dewachi, Pune

WP Function to redirect non-admin users to homepage of the website

April 10, 2014, by admin, category Wordpress

Many situation for members website we come across the issue that after logging in users getting redirected to the dashboard. In order to avoid this and redirect theme to the homepage use the following code.

function soi_login_redirect( $redirect_to, $request, $user  ) {
  return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url();
} // end soi_login_redirect
add_filter( 'login_redirect', 'soi_login_redirect', 10, 3 );

We may also needs to remove black wp admin bar for non-admin users. In order to do this you can use following code in your functions.php file.

add_action('set_current_user', 'cc_hide_admin_bar');
function cc_hide_admin_bar() {
  if (!current_user_can('edit_posts')) {

Comments are closed.