RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts</strong | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.69% (5.89%*) • Home Loan Fixed: 5.39% (6.59%*) • Fixed: 5.39% (6.59%*) • Variable: 5.69% (5.89%*) • Investment IO: 5.69% (6.48%*) • Investment PI: 5.39% (6.59%*)

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 complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

Like this article?

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

Leave a comment