Creating a Logout Button in Divi
Would you like to add a button to your Divi Builder pages to let your users logout? Here's how to do it.
Creating a Basic Logout Button
To create a simple logout button, you can just set the Button URL to something like this:
Replacing "https://www.mysite.com" with the URL of your site.
So your button module settings should look something like this:
When the user clicks the button, they'll be taken to a logout confirmation page from which they can complete the logout, like so:
Removing the Logout Confirmation
You may wish to get rid of the logout confirmation screen so that the user is logged out as soon as they click the button. You can do so by adding the following PHP code to your site (modified from this Stack Exchange answer):
Related Post: Adding PHP to the Divi Theme
(Note that this will disable the confirmation anywhere it would have been shown on your site, not just for this particular button.)
Clicking the button will now take you straight to the login form:
Redirecting to Another Page
While the steps above will create a button that logs the user out with a single click, it leaves them on the login screen, which may not be where you want them to end up. If you'd rather have them redirected to a different page once logged out, you can do so by modifying the Button Link to something like this:
The value of the "redirect_to" parameter in this link is the "URL encoded" form of the URL of the page you want the user to end up on. To get the URL encode form of a URL you can just paste your target URL into an online URL encoder.
In my example, my target URL is "https://www.mysite.com/welcome" and the encoded form is "https%3A%2F%2Fwww.mysite.com%2Fwelcome". Just replace this with your own encoded URL.
Now when the user clicks your logout button they should be logged out and redirected to the page you've specified.
Want get more out of Divi?
Hundreds of new features for Divi
in one easy-to-use plugin