How to logout from WordPress without confirmation

In this tutorial I will explain how you can create a logout link in Wordpress without confirmation. If you have a Wordpress theme with logout link, it will redirect you to the page where you need to confirm the logout.

To solve this problem, you must use the wp_loginout() function in your logout link.

Example:

<a href="<?php echo wp_logout_url(get_home_url()); ?>">Logout</a>

Inside of the wp_loginout() you must insert the url where the users will be redirect. wp_logout_url(get_home_url()) will redirect users on Home Page.

Now, your logout link will works well!

 









Leave a Comment

admin
admin commented on July 1, 2015
php code: $url = wp_logout_url(get_home_url()); And bellow javascript href="echo $url" I can't use this the php tags.

sridhar R
sridhar R commented on July 1, 2015
How to use it inside a javascript like supplying the href a url