Jan
29
2009
Issue with the User Logout Button in WordPress 2.7
I noticed a small issue in WordPress 2.7 when I was designing a login bar at the top of a client’s site and the logout link would not log the user out. I had coded the same way I had coded a logout button in the past, but it wouldn’t function properly. That is because WordPress 2.7 uses a new function to log a user out.
Here is the code I use to use:
<a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout">Logout</a> |
And here is the new code I now use:
<a href="<?php echo wp_logout_url() ?>">Logout</a> |
And here is a little bit of spice to make it redirect back to the current page:
<a href="<?php echo wp_logout_url(get_permalink()); ?>" >Logout</a> |
Nore: If you are using an theme that was designed before 2.7, you should go into your comments.php file and change the anchor tag around line 78 to fix your Logout link.



hello i aslo have a problem with logout when using the wordpress 2.7 in my site..
when i click logout it takes me to a page where it shows the msg
“You are attempting to log out of this site
Please try again.”
with “wp-login.php?action=logout&redirect_to=http://www.abc.in”
at the top navigation bar…
and when i click on “Please try again” which is a link i get redireted to the home page…
can u help me with this …cuz am new to using wordpress….
Hey Jeff,
I would have to take a look at your site. What is your URL?
This is going to seem dumb … but where do I drop that code? (which template)?
I would LIKE it to just be in the Links section (where the default is “Blogroll”, but if not possible, then either somewhere on the sidebar or toward the top of the screen.
The data on the site is of a highly personal nature, so I don’t want the 1 other person who has access to accidentally leave it open for anyone walking by! grin
THANKS!
T
Bavota.. Awesome job my friend… I browsed 100′s of sites with so many explanations.. your post was a quick fix. I wish i read this post the first. Keep posting!!!
I agree with Mahmood.
You explain it very clearly and direct to what you really wanted to imply.I don’t personally used WordPress 2.7, but my colleagues are the one who used this most of the time.I also heard them like this problem and i think they also made a way to fix the problem.Well anyway I’ll tell them about this.
Hi there. Will this work on the latest WordPress version 3.1?
Yes. That function still works in the latest release of WordPress.
Thank you! Life just got simpler. Quick question. On wordpress and plug-in updates I am spending large ammounts of time saving data prior to installing the update per the directions. Is this necessary? Is there a faster way?
If you have an automated backup setup then the backup portion would be done for you.