Title: Logout Feature Code Snippet
Last modified: February 13, 2021

---

# Logout Feature Code Snippet

 *  [caoimhinrafferty](https://wordpress.org/support/users/caoimhinrafferty/)
 * (@caoimhinrafferty)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/logout-feature-code-snippet/)
 * Hi,
    My site has a login feature for customers if they want to login. The problem
   I have is currently when a customer logs in there is not option and/or button
   to log out.
 * I have added the below code to the Snippets plugin but the logout feature is 
   not working.
 * Could you please help me with this and let me know where I am going wrong?
 * /**
    * Add a WooCommerce logout page shortcode button */
 * // Shortcode Action hook
 * add_shortcode( ‘wc_logout_shortcode’, ‘njengah_wc_logout_shortcode’ );
 * // Callback
 * function njengah_wc_logout_shortcode(){
 *  ob_start();
    // Check if user is logged in if (is_user_logged_in()){ // Create
   the url variable $wc_shortcode_logout_url = site_url() . ‘/?customer-logout=true’;?
   > <button class=”wc_logout_shortcode_btn”>“>Log Out</button> <?php }
 *  return ob_get_clean();
    }
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Flogout-feature-code-snippet%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/logout-feature-code-snippet/#post-14165603)
 * It doesn’t look like you’re attaching the link URL to the button in any way. 
   I’d recommend switching out this line:
 * `<button class="wc_logout_shortcode_btn">Log Out</button>`
 * for this:
 *     ```
       <a href="<?php echo esc_url( $wc_shortcode_logout_url 
        );" class="wc_logout_shortcode_btn">Log Out</a>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Logout Feature Code Snippet’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/logout-feature-code-snippet/#post-14165603)
 * Status: not a support question