Title: Logout Button
Last modified: August 22, 2016

---

# Logout Button

 *  [markimark3269](https://wordpress.org/support/users/markimark3269/)
 * (@markimark3269)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/logout-button-4/)
 * Hi there,
    for me, the most confusing part is not to have any logout button. 
   Is there any chance to achieve such a button, that redirects to another website.
 * My scenario and I think it is a typically one, is like this:
    Within a wp multisite
   installation, I have a default, public website but the menu is also containing
   a link to a password protected site (for distributors only). If a distributor
   has logged in to the password protected site, he should be able to logout from
   there and get redirected back to the default site, where he was coming from.
 * Does that make sense, is there any way to make this happen for me, maybe in combination
   with another plugin, that works fine with this one?
 * Any help is appreciated.
 * Mark
 * Update
    I think I could fake this with a button that only redirects to the default
   website but for this, the cookie can be only valid for 1 session, otherwise this
   would be confusing.
 * What do you think?
 * [https://wordpress.org/plugins/password-protected/](https://wordpress.org/plugins/password-protected/)

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

 *  [ta_grant](https://wordpress.org/support/users/andrewgrantcarbon60com/)
 * (@andrewgrantcarbon60com)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223925)
 * Hello,
 * +1 for this request! I’m looking at implementing a manual ‘log out’ link or button
   as well and have resorted to trying to manually invalidate the cookie in PHP.
 * `setcookie("bid_1_password_protected_auth", "", time()-3600);`
 * This seems to work occasionally in chrome for some reason, and does not want 
   to work correctly in firefox (from what I can gather, this may be a ‘feature’
   of firefox session restore).
 * Any help regarding this would be greatly appreciated!
 *  [ta_grant](https://wordpress.org/support/users/andrewgrantcarbon60com/)
 * (@andrewgrantcarbon60com)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223926)
 * Apologies, I believe my previous post may have actually hijacked this thread.
 * Thought I’d update this post regardless as I’ve found the solution to my issue
   in a separate thread here: [https://wordpress.org/support/topic/unable-to-logout](https://wordpress.org/support/topic/unable-to-logout).
   Maybe this will help?
 * if you simply append `password-protected=logout` to the query string, for instance:
   `
   <mysite.tld>/?password-protected=logout` then this should force a logout.
 * Another plugin I had investigated for our use case was [https://premium.wpmudev.org/project/sitewide-privacy-options-for-wordpress-mu/](https://premium.wpmudev.org/project/sitewide-privacy-options-for-wordpress-mu/)
   which only works on multi-site installs. This may be what you’re looking for,
   but is unfortunately, a premium, paid plugin.
 * Thanks!
 *  [Ben Huson](https://wordpress.org/support/users/husobj/)
 * (@husobj)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223927)
 * Yes, you can logout by appending “?password-protected=logout” to the URL.
 * So if you want to create a logout link it would be something like this:
 * `<a href="<?php echo add_query_arg( 'password-protected', 'logout', home_url());?
   >">Logout</a>`
 * If you want to redirect elsewhere I think you should be able to specify a URL:
 * `<a href="<?php echo add_query_arg( array( 'password-protected' => 'logout', '
   redirect_to' => 'http://wordpress.org' ), home_url() ); ?>">Logout</a>`
 *  [ta_grant](https://wordpress.org/support/users/andrewgrantcarbon60com/)
 * (@andrewgrantcarbon60com)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223928)
 * Thanks so much for confirming Ben!
 *  [thebuilder](https://wordpress.org/support/users/cway/)
 * (@cway)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223956)
 * Where would you put that log-out coding? I tried in a widget, but that didn’t
   work. I got a page not found.
    Thanks!
 *  [Ben Huson](https://wordpress.org/support/users/husobj/)
 * (@husobj)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223957)
 * If you want to do it in a widget you could just put a link to your home page 
   with the query on the end. Eg
 * [http://example.com/?password-protected=logout](http://example.com/?password-protected=logout)
 * `<a href="http://example.com/?password-protected=logout">logout</a>`
 *  [thebuilder](https://wordpress.org/support/users/cway/)
 * (@cway)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223958)
 * But that’s going to show even if they’re not logged-in. Is there some smart coding
   that provides a log-in link when they’re not logged-in, and a log-out link when
   they are logged-in?
 *  [Ben Huson](https://wordpress.org/support/users/husobj/)
 * (@husobj)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223959)
 * True 🙂
 * You might need install the PHP widget so you can use the PHP code in there:
    
   [https://wordpress.org/plugins/php-code-widget/](https://wordpress.org/plugins/php-code-widget/)
 *  [thebuilder](https://wordpress.org/support/users/cway/)
 * (@cway)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223960)
 * Done, and that works, but it always displays the logout link, even when you’re
   logged-out.
 * I found the WordPress is_user_logged_in code and put it in the php code widget,
   but it always shows “Welcome, visitor!” whether I’m logged-in or not. Below is
   that code. I’m not sure what’s not working – the php code widget, the is_user_logged_in
   code, or something else.
 * Has anyone else tried this?
 *     ```
       <?php
       if ( is_user_logged_in() ) {
       	echo 'Welcome, registered user!';
       } else {
       	echo 'Welcome, visitor!';
       }
       ?>
       ```
   
 *  [thebuilder](https://wordpress.org/support/users/cway/)
 * (@cway)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/logout-button-4/#post-5223961)
 * I noticed a few log-out options are available in version 2.0, they don’t seem
   to work, however. I’ve tried the below examples in a text widget and on a page.
   When I’m logged-in, the log-out links don’t show. Has anyone else had any luck?
 * I’m using WordPress version 4.1.1, version 2.0 of Password Protected, and version
   1.0 of included Twenty Fifteen theme.
 *     ```
       [password_protected_logout_link]Logout?[/password_protected_logout_link]
   
       [password_protected_logout_link text="Log me out" /]
   
       [password_protected_logout_link redirect_to="http://trailwoodhoa.com/" /]
       ```
   
 *  [Ben Huson](https://wordpress.org/support/users/husobj/)
 * (@husobj)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/logout-button-4/#post-5223962)
 * I don’t think the Text Widget supports short codes.
    Try installing and using
   the [Shortcode Widget plugin](https://wordpress.org/plugins/shortcode-widget/).

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

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

 * ![](https://ps.w.org/password-protected/assets/icon-128x128.gif?rev=2824217)
 * [Password Protected — Lock Entire Site, Pages, Posts, Categories, and Partial Content](https://wordpress.org/plugins/password-protected/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/password-protected/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/password-protected/)
 * [Active Topics](https://wordpress.org/support/plugin/password-protected/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/password-protected/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/password-protected/reviews/)

 * 11 replies
 * 4 participants
 * Last reply from: [Ben Huson](https://wordpress.org/support/users/husobj/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/logout-button-4/#post-5223962)
 * Status: not resolved