0

How can someone (that has access in Admin area (/wp-admin/) backend), when he is already logged in, and he wants to logout (default WordPress Logout) but only from inside this area, to be redirected to home page?

Something like this

add_action('wp_logout','redirect_after_logout');
function redirect_after_logout(){
if(/*logged in user is inside the admin backend area and wants to log out from there */) {
wp_redirect(home_url());
exit();
  }
}
  • What i actually want in a simple way is, when user is in the admin area (back end) and hit the default log out, just redirect him to home page, but when he is in the front end redirect him to current page (same page) he hitted the log out. Any help appreciated. – Honoluluman Oct 23 '17 at 17:47
  • (I am not sure if i should try with logout() or log out url() ) – Honoluluman Oct 23 '17 at 17:49
1

For your if condition, use the is_admin function to determine if the user is currently viewing a backend administrative dashboard page or are on the frontend of the site.

So your code above would resemble:

add_action('wp_logout','redirect_after_logout');

function redirect_after_logout(){
  if( is_admin() ) {
    wp_redirect( home_url() );
    exit();
  }
}

For more information, see the codex documentation at https://codex.wordpress.org/Function_Reference/is_admin

  • Thanks for your fast reply. I tested but unfortunately it doesn't seems to work . When user is in the admin area, and try log out just returns me to wp-login. It does not redirect. Any ideas? – Honoluluman Oct 21 '17 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.