https://idea-hack.com/blog/35754/
How to output the logout URL in WordPress

How to output the logout URL in WordPress

I will show you how to create the original WordPress logout button and how to output the logout URL. This is useful if you are building a membership service and want to provide an original logout button, or if you’re going to add a query to the logout button.

How to output WordPress logout URL

The easiest way to output a WordPress logout URL is to use “wp_logout_url.”

How to use “wp_logout_url”

php
<? php
echo '<p> <a href="'. wp_logout_url().'"> Sign out </a> </ p>';
?>

However, “The logout button is displayed even if you are not logged in” with this code.

If you want to show the logout button only when you are logged in, you need to modify the code.

Show the logout button only when logged in to WordPress

php
<? php
// Display logout button only while logged in
if (is_user_logged_in ()) {
echo '<p> <a href="'. wp_logout_url().'"> Sign out </a> </ p>';
}
?>

Only by this, the button for logout will not be displayed to those who are not logged in to WordPress, and “Logout” will be displayed only to those who are logged in.

All you have to do is add a class and decorate it with CSS, and it’s your original logout button!

You can do it only with copy, so please try it.