Recently, I was debugging an issue with logout for a friend who was running a WordPress blog. His theme had a logout button in the sidebar, which stopped working after he upgraded to the latest version of WordPress from a pretty old version.
After some debugging, I found that the nonce value was missing from the logout link. In older versions of WordPress, the nonce value was needed, but in newer versions, we need to pass the nonce value to perform the logout.
We need not append the nonce value manually, instead we can use build-in function
wp_logout_url(). This function will automatically append the nonce value to the logout link.
If you want the user to be redirected to the current page he is viewing, after logging out, you can use the following code snippet.
<a href="<?php echo wp_logout_url();?>&redirect_to=<?php echo $_SERVER['REQUEST_URI']; ?>"><?php _e('Logout'); ?></a>
- WordPress Developer tools to increase productivity in WordCamp Mumbai
- Email Log WordPress plugin v1.9.1 released
- Email Log WordPress plugin v1.9 released
- How to find if you are on the last page of a multi-page post in WordPress
- Easy Retweet WordPress plugin v3.1 Released
- Creating custom tables with correct Character Set and Collation in WordPress