Two useful login/logout WordPress functions

If you’re running a WordPress E-commerce site and you have the need for customer login but don’t want your customers accessing the admin area you can add this code to your functions.php file and the top admin bar will not be displayed.

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
     if (!current_user_can('administrator') && !is_admin()) {
          show_admin_bar(false);
     }
}

You may also want to redirect your customers to a specific page after they have logged out. You can redirect users to the homepage by adding the following code.

add_action('wp_logout','go_somewhere');
function go_somewhere(){
  wp_redirect( home_url() );
  exit();
}

Previous

No Comments

Leave a response