WP Logout link

I have been playing with WordPress recently, and of course faced some challenges.
One of them is having a simple link to logout WordPress, just like login
for login, you can easily link to…
/wp-login.php
For register, you do
/wp-login.php?action=register
But that is not as simple if you want to logout, you need to pass another argument (called _wpnonce) which looks like a session ID that is changed every login.
That makes it almost impossible to allow logging out using a simple link, unless you install some plugins.
So after some playing, I was actually able to do that by adding new php file.
I called wp-logout.php and placed it in my website root.
This way, I can call it anywhere I want to logout the current user
Either download attached or use code below

<?php
/*
******** wp-logout.php to Logs-out WordPress, works for current logged in user ********
Save this as "wp-logout.php" into your wordpress root folder, like http://mysite.com/wwwroot/wp-logout.php
Then call it to log out the website and redirects to root
http://mysite.com/wp-logout.php
Enjoy
*/
require( dirname(__FILE__) . '/wp-load.php' );
$user = wp_get_current_user();
wp_logout();
wp_safe_redirect( '/' );
?>

Views 595 Downloads 292

'Wordpress', 'Wordpress', 'wp', 'logout', 'login', 'user', 'sessions'

ANmarAmdeen
333
Attachments
Sessions PHP
Revisions

v1.0

Needs