Title: Logout Widget
Last modified: August 20, 2016

---

# Logout Widget

 *  [sblob](https://wordpress.org/support/users/sblob/)
 * (@sblob)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/)
 * I have created a custom login/logout widget on the sidebar. However when a logged
   in user clicks “logout” it gives the following error: WordPress Failure Notice.
   You are attempting to log out of `websitename`
    Do you really want to log out?
   The actual code for the logout link I am using is: `<a href="http://www.websitename/
   wp-login.php?action=logout" alt="logout" title="Logout">Logout</a>`
 * I have also tried using this code:
    `<a href="<?php echo wp_logout_url(); ?>"
   title="Logout">Logout</a>` But then I get the following error: Error 404 – Page
   not found! The page you trying to reach does not exist, or has been moved. Please
   use the menus or the search box to find what you are looking for.
 * The site of concern is [http://www.aintreelane.co.za](http://www.aintreelane.co.za)
 * Would anyone be able to assist with this?
    Is this a theme problem or something
   I am doing wrong? Thanks in advance!

Viewing 14 replies - 1 through 14 (of 14 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246360)
 * I’ve implemented a custom login/logout widget in [one of my themes](http://quirm.net/themes/emporium/).
   Perhaps you could download it and grab the code that I used?
 *  Thread Starter [sblob](https://wordpress.org/support/users/sblob/)
 * (@sblob)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246361)
 * That would be great! Which theme should I download to find the code?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246363)
 * Emporium. Have a look at /library/login-widget.php. The script is loaded using:
 *     ```
       // Load login form widget
       function emporium_load_login_widget() {
       	include_once get_template_directory() . '/library/login-widget.php';
       	if( function_exists ( 'wp_login_form' ) ) register_widget( 'Emporium_Login_Widget' );
       }
       add_action( 'widgets_init', 'emporium_load_login_widget' );
       ```
   
 * in functions.php
 *  Thread Starter [sblob](https://wordpress.org/support/users/sblob/)
 * (@sblob)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246364)
 * Thank you, I appreciate your help!
 * My previous query was dumb as you already linked to emporium.
 * I have tried using your code and it gives me the same issue: I am getting a 404
   error.
    Unfortunately I don’t know enough php to solve why this is happening.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246371)
 * The WordPress failure might be because you are not providing a nonce parameter
   to wp-login.php.
 * Not sure about the 404 error. Any chance your theme or a plugin is filtering ‘
   site_url’ or something similar? Also, confirm the url you entered in the admin
   settings is correct. I once had a similar problem and found the wordpress url
   somehow got set to something like `http:\\http:\\www.sample.com`
 *  Thread Starter [sblob](https://wordpress.org/support/users/sblob/)
 * (@sblob)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246376)
 * The URL I entered in the admin settings seems fine.
    The code I am currently 
   using is: `http://www.aintreelane.co.za/wp-login.php?action=logout`
 * Do you know I link where I can read more about nonce parameters? I’m not sure
   what parameter parameter to insert?
    Sorry for noob questions!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246390)
 * Everyone here was a noob once 🙂
    The overview is [WordPress Nonces](http://codex.wordpress.org/WordPress_Nonces)
   FYI, the logout action checks the passed nonce with `check_admin_referer('log-
   out');` which means you should do something like
 *     ```
       $logout_url = 'http://www.aintreelane.co.za/wp-login.php?action=logout';
       $logout_url = wp_nonce_url( $logout_url, 'log-out' );
       ```
   
 * which should yield something like `http://www.aintreelane.co.za/wp-login.php?
   action=logout&_wpnonce=cfb7bcd268` .
 *  Thread Starter [sblob](https://wordpress.org/support/users/sblob/)
 * (@sblob)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246395)
 * So that code should go into my php somewhere?
 *  [truthseeker83](https://wordpress.org/support/users/truthseeker83/)
 * (@truthseeker83)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246396)
 * `<a href="<?php echo wp_logout_url(esc_url( home_url( '/' )); ?>" title="Logout"
   >Logout</a>`
 * **try this it takes you to homepage**
 *  Thread Starter [sblob](https://wordpress.org/support/users/sblob/)
 * (@sblob)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246397)
 * Hi Truthseeker, thanks for the help.
    Unfortunately that code gives me a 404 
   error 🙁 Page not found…
 * When I use the standard wordpress meta widget the logout link works fine. Is 
   there a way to see what code they use in that widget link?
 *  [truthseeker83](https://wordpress.org/support/users/truthseeker83/)
 * (@truthseeker83)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246398)
 * sorry a bracket was missing
 *     ```
       <a href="<?php echo wp_logout_url(esc_url( home_url('/'))); ?>" title="Logout">Logout</a>
       ```
   
 * takes to home page on logout
 *  Thread Starter [sblob](https://wordpress.org/support/users/sblob/)
 * (@sblob)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246399)
 * Still the same issue 🙁
 * Error 404 – Page not found!
 * The page you trying to reach does not exist, or has been moved. Please use the
   menus or the search box to find what you are looking for.
 * Is this code you provided the code that the meta widget logout uses? Do you know
   if there is a way to find this code?
 * Really appreciate all the help!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246401)
 * > So that code should go into my php somewhere?
 * Right, the output of wp_nonce_url() should be the href for the link the user 
   clicks to logout.
 * The Meta widget source is in wp-includes/default-widgets.php, around line 298.
   You’ll find it simply calls wp_loginout(), which will display the appropriate
   link depending on the user’s status of in or out. If you check it’s source, you’ll
   see it uses wp_nonce_url() as well.
 *  Thread Starter [sblob](https://wordpress.org/support/users/sblob/)
 * (@sblob)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246405)
 * That is what I thought. I can’t figure out why my custom link won’t work but 
   the logout meta widget works.
    Will check the source out!

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Logout Widget’ is closed to new replies.

## Tags

 * [Logout](https://wordpress.org/support/topic-tag/logout/)
 * [widgets](https://wordpress.org/support/topic-tag/widgets/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 14 replies
 * 4 participants
 * Last reply from: [sblob](https://wordpress.org/support/users/sblob/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/logout-widget/#post-3246405)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
