Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Logout Redirect and also WP-login.php Redirect

you can do that with this code (paste it to your functions.php)

function auto_redirect_external_after_logout(){
    // check if user is leaving from admin
    // is_admin() check would not work here probably as we left the admin already
    if ( false !== strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) ){
        wp_redirect( 'http://www.example-from-admin.com' );
    } else {
        wp_redirect( 'http://www.example-from-front.com' );
    }
    //make sure to call exit after redirect
    exit;
}

//execute the code above on logout
add_action( 'wp_logout', 'auto_redirect_external_after_logout');

Related Posts:

  1. Masking logout URL
  2. Logout/login redirect CSS issue
  3. redirect wp-login.php to another page
  4. How do I redirect upon login a specific user based on role?
  5. Login Redirect if Logged in from Specific Page
  6. Add Login and logout buttons to top menu bar
  7. How to redirect Subscribers on login to specific page, when logging in from a Page
  8. How to request login for user but not for bots
  9. Redirecting after login except for a specific page
  10. wp_enqueue_script was called incorrectly
  11. How do I get the current edit page ID in the admin?
  12. How to change the default logout link on WordPress Admin
  13. Modify Admin Bar Link
  14. Logout redirect to current page – function
  15. How to remove row-actions from pages table?
  16. Is it possible to remove the main rich Text box editor?
  17. Add admin bar link to edit author
  18. handling login/logout redirects
  19. How can I tell if I’m on a login page? [duplicate]
  20. Is it possible to use a forgot password url filter?
  21. Paged Single Post doesn’t redirect to the main url after Removing Pagination
  22. Replacing select2 in admin backend for all selects
  23. echo or print_r in an admin function
  24. Can I remove the Rich Text box editor for a specific post?
  25. Login using the password from protected pages
  26. Logging in redirects to correct page but shows logged out content until forced refresh
  27. Redirect user after logout
  28. wordpress custom login successful redirect hook
  29. I keep getting logged out in Firefox
  30. How to add a column to the Trash page?
  31. How to test for Super Admin
  32. Remove default user registration, login and subscriber profiles
  33. is_user_logged_in not working to redirect only logged out users
  34. How to select a page within admin?
  35. Members only site – still need the lost password page accessible
  36. Change Admin Bar “Visit Site” URL
  37. Ninja form Redirect depending on text field content [closed]
  38. Redirect specific page in WordPress for first time visit
  39. How do I redirect all 404 error url to Subcategory url
  40. How to change login labels
  41. How to Display Frontend CSS for Administrator only
  42. Login/logout in header
  43. Can’t login to my admin area
  44. Page get parameter doesn’t work with is_single() function
  45. Secondary Menu and Logged In Users
  46. Redirect website domain (including all pages) to external URL after Popup message (few seconds)
  47. Contact Form 7 If Condition
  48. Prevent WordPress Automatic Logout
  49. error at login page in wordpress
  50. Solved: redirect to another page using functions.php
  51. Redirect to other page if login
  52. Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
  53. logout redirect only from admin page
  54. How to add array [closed]
  55. what is best way to keep track of changes made in wordpress website? [closed]
  56. WordPress wraps span tags into p tags
  57. WordPress website keeps loading the maintenance page
  58. Redirects based on a JSON file
  59. loginout function customization
  60. Creating a custom wordpress widget and stopping js from running twice(once in active widget once in widget selector)?
  61. Show errormessages on wrong username/password on custom loginform?
  62. template_redirect action only firing if logged in
  63. Removing WPML Items From the WordPress Admin Bar
  64. WordPress login set cookie that survive browser exit (wp_signon function)
  65. This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise
  66. Prevent wp_signon redirect on failed login for ajax login
  67. Show metadata in users.php – wordpress
  68. Redirect to one of two pages after data submitted, depending on the current url
  69. How to replace ACTION url from original wordpress login form?
  70. How to display my comment count in the wordpress admin bar?
  71. Unable to login after registration
  72. Allow logged in user to view a Page, else send to login screen and then redirect back to Page
  73. Wildcard 301 Redirect Using Theme Function
  74. Competing Login Redirects – Need to be Combined?
  75. Postback redirect through add_action is not triggered
  76. Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
  77. Restrict access if logged out except for homepage
  78. Redirect specific author posts to another url
  79. Trying to login to my site redirects me to the first page
  80. Custom download page
  81. Redirect after login to current URL
  82. How to create a function to redirect a specified page to another page
  83. Multisite Admin Roles
  84. Login functions
  85. Language switcher for subdomains
  86. WordPress permanently logging users out
  87. Logging back into WordPress after logging out and having issues with ‘loggedout=true’ in redirect URL
  88. Allow the access over wp-login.php
  89. WP Logs me out after updating anything on dashboard
  90. function to return comma separated list of meta values
  91. Screen Options WordPress WYSIWYG
  92. is_user_logged_in() isn’t working
  93. update_user_option not working as expected
  94. “Headers already sent” while trying to add a CSS file to my login page?
  95. Making an under maintenance page (without using plugins)
  96. Logout redirect via page template without confirmation?
  97. Template Redirect Function Only Working When Logged In
  98. Disable Attachment Page Except for Category
  99. Simple way to make most of my site private
  100. wp_login_form display no styled form
Categories functions Tags admin, functions, login, logout, redirect
How do I not embed the SoundCloud player? I just want the link
Allow user edit widgets

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress