RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Redirect Logged in Users to Front Page

If you have a member-based website and don't want to provide access to the back end, the following filter will redirect users upon login to the front page.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Redirect Subscriber WordPress Users to Front Page After Login
4
 http://www.beliefmedia.com/code/wp-snippets/redirect-users
5
*/
6
 
7
function beliefmedia_login_redirect( $url, $request, $user ){
8
  if ($user && is_object($user) && is_a($user, 'WP_User')) {
9
    if($user->has_cap( 'administrator')) {
10
      $url = admin_url();
11
       } else {
12
      $url = home_url('/');
13
    }
14
  }
15
 return $url;
16
}
17
add_filter('login_redirect', 'beliefmedia_login_redirect', 10, 3 );

The next function will redirect a user upon requesting an admin page.

1
<?php 
2
/*
3
 Redirect Logged in Users to Front Page
4
 http://www.beliefmedia.com/code/wp-snippets/redirect-users
5
*/
6
 
7
8
  if (!current_user_can('manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF']) {
9
    wp_redirect( home_url() );
10
    exit;
11
  }
12
}
13
add_action( 'admin_init', 'beliefmedia_redirect_non_admin_users' );

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment