• Skip to primary navigation
  • Skip to main content
  • Skip to footer

WPJohnny

WordPress Performance Guides and Reviews

  • Start a WordPress site
  • Hosting
  • Themes
  • Plugins
  • Blogging
  • Marketing

Custom LOG OUT link without WP-nonce confirmation

WordPress themes Dec 8, 2021 by Johnny 19 Comments

Quick guide for anyone trying to create their own custom log out links (from a menu or within their content).

So what’s the issue?

  • You create a logout link to https://domain.com/wp-login.php?action=logout
  • But when you visit it…it asks for a confirmation. Annoying, right?

So to get past that we add a little snippet to functions.php (in your child theme).

The fix

Paste this snippet into your functions.php but replace yourdomain.com. And now you can create your own users logout link anywhere you like!

add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
    /**
     * Allow logout without confirmation
     */
    if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
        $redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : 'https://yourdomain.com';
        $location = str_replace('&', '&', wp_logout_url($redirect_to));
        header("Location: $location");
        die;
    }
}

What about other fixes?

Long story short, I wrote this guide because the other fixes didn’t work. If you have other solutions to share, let me know in the comments.

Share this post:

Share on FacebookShare on X (Twitter)Share on LinkedInShare on WhatsAppShare on EmailShare on SMS

Read all my posts on WordPress themes

About Johnny

Right on the edge of WordPress development! 10+ years of WordPress design, development, hosting, speed optimization, product advisor, marketing, monetization. I do all that.

More WordPress Guides

How to FINISH your web design project (without delay)

Writing Tips for First-Time Bloggers

Should you load Google Analytics in HEADER or FOOTER?

10 Best WordPress SECURITY plugins review

301 Redirects to HTTPS (with and without WWW)

Removing WordPress user registration spam

Reader Interactions

19 Comments

  1. ywl

    February 25, 2022 at 9:44 am

    I just accidentally found your website and it’s the most beautiful and well-designed one I have ever seen. Also thank you very much for writing such useful articles!I have saved the website to my bookmark and will come back regularly

    Just a little thing to tell you(actually it’s why I leave a comment) that the email button to share this post turn white when hovered, the background is incorrectly set to #fff, this really bother me, so please fix it when you are not so busy

    Hope you have a great day!

    Reply
  2. Julian

    March 19, 2022 at 6:34 am

    I had this issue before, noticed that a new plugging that I had just installed a few hours before, had the setting to block the /wp-login.php path lol

    Reply
  3. Sarah

    July 2, 2022 at 6:13 pm

    This was EXACTLY what I was looking for!!! I have tried numerous other code snippets and this works perfectly. Thank you!

    Reply
  4. Xtof

    September 9, 2022 at 1:18 am

    Thanks Johnny
    Same case as Sarah, tried numerous ones ans yours works just fine 🙂

    Reply
  5. Tin

    September 27, 2022 at 7:25 pm

    Well, I’ll be damn!!! I too have been trying different snippets and this one finally worked. Thank you Johnny.

    Reply
  6. Esme

    November 5, 2022 at 9:37 am

    Thanks so much for sharing this clever tidbit!

    Reply
  7. Craig

    November 10, 2022 at 4:19 am

    Thank you so much for this snippet. It works a treat.

    Reply
  8. Protos

    February 3, 2023 at 4:57 pm

    You saved us! We tried the same solution as you had with no luck, fortunately we found your site and it works flawlessly. Thank you so much!

    Reply
  9. abadi

    May 5, 2023 at 1:43 pm

    Thank you so much.

    Reply
  10. Anton

    July 3, 2023 at 12:10 am

    Thank you so much

    Reply
  11. Matthias

    July 27, 2023 at 4:40 am

    I changed my login url with WPS Hide login. The snippet is not working because wp-login.php is not used anymore. Is there a modify possible to the snippet?

    Reply
  12. Kim

    August 14, 2023 at 4:05 pm

    This code works great. Thank you. I needed something to use for a button URL. Again thanks.

    Reply
  13. Nesia

    September 26, 2023 at 3:27 am

    Thank you very much bro

    Reply
  14. Diffusioni Musicali

    October 11, 2023 at 6:39 am

    it does not work 🙁
    https://diffusionimusicali.org/logout/?_wpnonce=fff32fe325

    Reply
  15. Mahesh Dubal

    January 9, 2024 at 5:56 am

    It works, Thank you

    Reply
  16. Randy Gallagher

    February 22, 2024 at 5:44 am

    I get a 418 using this.

    Reply
  17. Kea

    March 29, 2024 at 7:33 am

    Worked like a beautiful charm. Thank you

    Reply
  18. Chris

    April 6, 2024 at 9:54 am

    Wow! Thank you so much, this is exactly what I was looking for! It just works great!

    Reply
  19. Mark

    July 17, 2024 at 12:24 am

    Why is it that every time I find a script on your website, it just works!👍 I should probably just come here and search before using Google from now on. Usually I get Stackoverflow and it gets tiring trying script after script to no avail. Anyways, when google finally got me here, I recognized your name and website and had a feeling it was going to work. Keep up the good work! I wish I knew 1/100th of what you do.

    Reply

Leave a Reply to Mahesh Dubal Cancel reply

Your email address will not be published. Required fields are marked *

Footer

More links

  • Gadget reviews
  • Try my free WPJ plugins
  • Join the WPJ FB Group
  • WPJ YouTube & newsletter
  • Become a WPJ Affiliate

Popular Reviews

  • Best WordPress Hosting
  • Best WordPress Themes
  • Best WordPress Plugins
  • Best WordPress Cache Plugins

Services

  • Speed optimization
  • Speed optimization courses
  • WordPress hosting
  • Hire me or other experts
  • Client login

About Johnny

10+ years of WordPress design, development, hosting, speed optimization, marketing.
Contact me.

newsletter block

Copyright 2025 | WordPress guides by Johnny Nguyen

Click to Copy