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

Log out without confirmation request (nonce)

Using wp_logout_url() is your best choice.

You will need to create a <a> tag and in the href attribute output wp_logout_url()

<a href="<?= wp_logout_url("https://wordpress.stackexchange.com/"); ?>" title="Logout">Logout</a>

I passed / as an argument because after the user will click the link he will be redirected back to the homepage, you can change it to what ever you want

EDIT

Using code snippets you could create a shortcode and then use it, almost, where ever you want.

add_shortcode('bt_custom_logout_link', 'bt_custom_logout_link');
function bt_custom_logout_link ($atts) {
    $link = '<a href="' . wp_logout_url("https://wordpress.stackexchange.com/") . '" title="Logout">Logout</a>';
    return $link;
}

This function will register a new shortcode named bt_custom_logout_link, to use it you need to type it like this [bt_custom_logout_link]

Related Posts:

  1. How to: PHP Log Out Link?
  2. Login/logout in header
  3. Check if user had autologin & if so, logout
  4. Change button link to add nonce
  5. Change Login or Logout text based on status
  6. User registration followed by automatic login
  7. Can I use the same nonce for multiple requests on the same page?
  8. How to use nonce with front end submission form?
  9. Adding “Remember Me” in custom login
  10. How to change the wp-login.php page title?
  11. How build a custom login/register form with error handling?
  12. Do I require the use of nonce?
  13. WordPress “Link has expired” error on updating posts
  14. How to log out everywhere else, destroy all sessions “all other devices”?
  15. Change the footer text on the login page
  16. Changing user_nicename
  17. Security – Ajax and Nonce use [closed]
  18. WordPress 4 invalid username special charachters issue
  19. How to place login logout link on menu that redirects users back to current page?
  20. How to turn off redirection from ‘domain.com/login’ to ‘domain.com/wp-login.php’
  21. How to resolve error “Cookies are blocked due to unexpected output.”?
  22. Using a nonce in a Custom Login Form
  23. Constructing a custom login form using ajax
  24. automated tests as a user?
  25. Remove username in emails or swap username for email
  26. woocommerce and is_user_logged_in() if not redirect to homepage
  27. When must I use and verify nonce?
  28. Check if user is logged in when clicking certain links on certain pages
  29. What SQL / WordPress queries would need a nonce?
  30. PHP If user is logged in & on home page redirect
  31. WordPress shows registration link for non logged users
  32. Creating login session via CURL
  33. Admin username and password
  34. Recovering WP Login Credintials in Code?
  35. WP nonce invalid
  36. Is it necessary to sanitize wp_set_password user input?
  37. WordPress custom login form using Ajax
  38. How to give new users two specific user role options upon WordPress user registration
  39. Wp-login appears White Screen, Error: Cannot modify header information
  40. Why is my cookie not unsetting upon logout? [closed]
  41. User management system similar to wordpress one?
  42. Programmatic Login from 3rd Party site
  43. Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
  44. How to debug my custom login form looping intermittently
  45. Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
  46. Why ajax doesn’t work on certain wordpress hooks?
  47. Are nonces in WP REST API optional by default?
  48. getting logged in user info (wp-load.php) from parent directory
  49. Problem with login form
  50. Login to wordpress by clicking a link and specifying usernaname and password in url
  51. Form Security: nonce vs. jQuery
  52. Log in / Log Out Custom Button
  53. Should `wp_login` be used since it’s deprecated?
  54. How to redirect users based on role and content of redirect_to?
  55. Change CSS based on is_user_logged_in
  56. How to display login form anywhere, when user isn’t logged in, without redirecting?
  57. How can I open up my administrative panel to everyone?
  58. Force Users To Relogin
  59. How to hook a logout funtion for specific usr role in wordpress?
  60. How can I add a new row in a separate database when someone registers via WordPress?
  61. One account with multiple logins
  62. How to use the wpsnonce clone post link?
  63. Lost in trying to create user database system
  64. Logout redirects to default page
  65. Shortcode to log user into current URL
  66. PHP getting error when trying to access WP-Admin Dashboard
  67. I installed WordPress locally now how do I login?
  68. If user is logged in not working
  69. Change homepage content if user is logged in – BuddyPress
  70. Show login greeting above sub-menu links?
  71. is_user_logged_in returning nothing on custom page
  72. Help with accessing wp-admin page and resolving error messages
  73. Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
  74. Can’t log in to WordPress wp-admin after adding code to functions.php
  75. Reliable way to add nonce to HTTP Header in WordPress?
  76. Admin Panel 404 Error after login
  77. PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
  78. How to block specific user id in custom login form?
  79. Having trouble creating two shortcodes, one for logged in user and one for visitors
  80. Call WP Rest-Api to GET /users/me returned NOTHING in console
  81. Restrict wordpress access to logged users only
  82. Infinite loop when logging out using custom login form
  83. Menu not updating for logged in users after redirect
  84. how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
  85. Issues adding Recaptcha v3 to WordPress Registration
  86. Display specific page if user signed in
  87. Refresh page after login with litespeed cache
  88. Redirect after login depending on the URL
  89. Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
  90. Redirecting the lost password page request when using a custon login page
  91. How do I send a POST request with params with WordPress REST API
  92. wp-login.php?redirect_to=https problem
  93. is_user_logged_in() not working in homepage
  94. Check if a user is logged into my WordPress site which is on a different server
  95. Newbie question. Login/Registration. New PHP page
  96. Adding a sidebar to wp-login.php
  97. List users in a dropdown for login
  98. Nonce fail after second submit attempt
  99. Not logged in when using http
  100. add bootstrap modal after login in wordpress
Categories PHP Tags login, logout, nonce, php
remove_action from parent theme using child theme functions.php
Does this archive template part look like its making too many calls to the db?

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