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

Redirect user after logout

You can use the wp_logout_url() template tag to generate a logout link. You can specify the URL that the user will be redirected to as the first pramiter:

wp_logout_url( 'http://example.com' );

The above code will generate a URL that looks a bit like this: /wp-login.php?action=logout&_wpnonce=ba51bbcdc3&redirect_to=http://example.com/unsubscribe. You can make it into a link like so:

<a href="https://wordpress.stackexchange.com/questions/77937/<?php echo wp_logout_url( home_url("unsubscribe' ) ); ?>" title="Logout">Logout & Unsubscribe</a>

If you want to use this in a page or post, you need to create a shortcode:

function wpse_77939_unsubscribe_link() {
    return sprintf(
        '<a href="https://wordpress.stackexchange.com/questions/77937/%s" title="Logout">Logout & Unsubscribe</a>',
        wp_logout_url( home_url( 'unsubscribe' ) )
    );
add_shortcode( 'unsubscribe-link', 'wpse_77939_unsubscribe_link' );

You can then add [unsubscribe-link] to a post or page where you want the link to appear.


If you’re redirecting to another website besides your own, you need to add this code to your functions.php file (replace example.com with the domain of the site):

add_filter( 'allowed_redirect_hosts','wpse_77938_allowed_redirect_hosts' );
function wpse_77938_allowed_redirect_hosts( $allowed ) {
    $allowed[] = 'example.com';
    return $allowed;
}

Related Posts:

  1. How to change the default logout link on WordPress Admin
  2. handling login/logout redirects
  3. Logging back into WordPress after logging out and having issues with ‘loggedout=true’ in redirect URL
  4. Redirect user to original url after login?
  5. Logout redirect to home page
  6. Login redirect to previous page
  7. Redirect to referring page after logging in
  8. check first time login only
  9. How to redirect after login, the working way?
  10. Masking logout URL
  11. Password change when the user login first time
  12. Custom login form redirect to external site
  13. Restrict Access to wp-login.php
  14. Using `auth_redirect` : keeps asking me to login even when I’m logged in
  15. Redirect users after first login
  16. Redirect to current page after wordpress login
  17. wp-login.php — redirect logged in users to custom URL
  18. wp_logout_url() redirects to confirmation page even with nonce?
  19. Redirect user after login/registration globally
  20. Redirect to login page
  21. You do not have sufficient permissions to access this page
  22. how to do logout redirect to current url
  23. How to redirect user to specific page based on the input password
  24. How do I redirect a user when he is logged in after clicking on a menu
  25. How to modify the Register link in the login page?
  26. Changing “Lost Password Email Link” to custom password reset page
  27. How to redirect user to a specific page based on username?
  28. Redirect after password update
  29. How to redirect user after login to a specific page?
  30. Redirect Logged In User if page is wp-login.php and $_Get[‘level’] = X
  31. Redirect when accessing /login when logged in
  32. How to redirect after login getting a variable from url (for example with the language)
  33. If User is NOT Logged in and Page ID is not 6 – Redirect to Login
  34. Redirect to Current Page after Login
  35. How to include error message on login
  36. Login redirect problem
  37. How to redirect on login to a specific page if a specific meta user is empty
  38. redirect Login problems
  39. Redirect user to previous page after signup from custom form
  40. How can I force the user to log in, even if they’re already authenticated?
  41. User is logged in after Stripe payment, then redirected, but is then logged out again
  42. After logout browser’s back button into twenty sixteen theme profile
  43. Login Redirect – Multiple Scenarios
  44. WooCommerce – Redirect to a product after login
  45. Usage of the login_redirect filter
  46. Login/Register redirect user with message
  47. Redirect user to original url after login?
  48. Prevent users from going to wordpress profile after login
  49. Logout without confirmation and SAME window on mobile
  50. Custom form redirect after login
  51. Custom redirect user after login based on metadata
  52. Custom Login Form – Redirect user to login page if not logged in
  53. Redirection on Custom page
  54. Redirect user to specific link after login
  55. Logout Redirect and also WP-login.php Redirect
  56. Load function with login_redirect
  57. Prevent “/login” to redirect to “/wp-login”
  58. Redirect User to login page
  59. All URLs Redirect to Main Page
  60. How to redirect user after login to the page called by his first name?
  61. redirect doesn’t work while using example code
  62. Why I am not able to direct user to my blog section without login?
  63. How to redirect logged out users to specific page?
  64. Redirect After Login Error
  65. Redirect certain pages if user logged in
  66. Force User Login
  67. wp_login_form redirect
  68. custom login form redirect problem
  69. Login redirect to previous page
  70. Trying to re-direct users to specific page based on an ACF variable
  71. Disable redirect to homepage after successful Login, Stay on Current Page
  72. Redirect to custom login page if not logged in and redirect to home if logged in user try to login, how?
  73. wp_login_form() redirect same page
  74. How force WordPress redirect to current custom page after login
  75. Hide a Post everywhere except on redirect
  76. Conditional Login Redirect
  77. Keep the old referrer after failed login
  78. Determine user destination on wp-login.php
  79. Redirect user after login to prior page through a wp_login hook
  80. How can force redirected to login for two or more pages to view or access
  81. How to redirect returning users who previously logged in?
  82. How to redirect user to Referrer Page using wp_signon in Custom Login Page in WordPress
  83. Redirect after login when WordPress in subdirectory
  84. HOW do you Redirect buddypress login to EDIT tab not PROFILE tab on profile page? [closed]
  85. Login redirects to home page and doesn’t log in
  86. WordPress not loggin user and redirecting after custom registration
  87. redirect_to ignoring the SSL
  88. Redirect user on login using extra field value on login form
  89. Woocommerce login to specific page or referrer
  90. wp-login.php redirect problem
  91. login redirect problem – db charset issue?
  92. How to modify the WordPress comes with redirect
  93. Conditional redirect on login using referring URL
  94. Redirect problem: How to redirect to the original URL after login
  95. Custom Login Plugin Redirects to wp-login.php After Site Migration
  96. Login Form Redirection
  97. Redirect user to login and then to page where they came from
  98. Conditional redirection with logout
  99. Custom, conditional redirect on logout
  100. WordPress Login Page redirecting after failed login
Categories redirect Tags login, logout, redirect
Custom search page and search by title, content and tag
How to no follow the paginated comments

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