# Creating a custom Log Out button

**URL:** <https://forum.wixstudio.com/t/creating-a-custom-log-out-button/1792>\
**Category:** Ask the community\
**Tags:** question, code, wix-members-area\
**Created:** [April 7, 2023, 1:09pm UTC](https://forum.wixstudio.com/t/creating-a-custom-log-out-button/1792 "2023-04-07T13:09:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hq66893](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hq66893/32/7872_2.png) [@hq66893](https://forum.wixstudio.com/u/hq66893)\
**Post date:** [April 7, 2023, 1:09pm UTC](https://forum.wixstudio.com/t/creating-a-custom-log-out-button/1792/1 "2023-04-07T13:09:26Z")

</div>

Hey guys!

If you’re trying to create a custom log out button for your wix-members website simply add this code to the page you need (or in your header/footer and it’ll work a treat!

Happy Coding!

```javascript
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';

$w.onReady(() => {
    $w("#button208").onClick(logoutAndRedirect);
});

function logoutAndRedirect(event) {
    Promise.all([wixLocation.to('https://www.stockshub.uk/'), wixUsers.logout()]);
}

```

And here’s how each line of code works:

// Import the ‘wix-location’ module to be able to navigate to a different URL  
import wixLocation from ‘wix-location’;

// Import the ‘wix-users’ module to be able to log out the current user  
import wixUsers from ‘wix-users’;

// Set an event listener to run the ‘logoutAndRedirect’ function when the button with ID ‘button208’ is clicked  
$w.onReady(() =\> {  
$w(“#YourButtonIDHere”).onClick(logoutAndRedirect);  
});

// Define the ‘logoutAndRedirect’ function, which logs out the current user and redirects to the desired URL  
function logoutAndRedirect(event) {

// Use Promise.all() to wait for both navigation and logout to complete  
Promise.all([wixLocation.to(‘YourWebsiteURLHere’), wixUsers.logout()]);  
}

---

<div class="post-metadata">

**Author:** ![Tommy\_Morano](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tommy_morano/32/83203_2.png) [@Tommy\_Morano](https://forum.wixstudio.com/u/Tommy_Morano)\
**Post date:** [November 23, 2023, 6:38am UTC](https://forum.wixstudio.com/t/creating-a-custom-log-out-button/1792/2 "2023-11-23T06:38:30Z")

</div>

> [@hq66893](#):
>
> ```javascript
> import wixLocation from 'wix-location';
> import wixUsers from 'wix-users';
> 
> $w.onReady(() => {
> $w("#button208").onClick(logoutAndRedirect);
> });
> 
> function logoutAndRedirect(event) {
> Promise.all([wixLocation.to('https://www.stockshub.uk/'), wixUsers.logout()]);
> }
> 
> ```

Hello, this does not seem to take the user to a specific page on my site, i copied and pasted the code and modified the desired URL it only takes them back to the lightbox to sign in. do you have any tips or what I can be doing wrong?

Thank you
