Post Pic

How to: Create a “Logout” button on your WordPress blog

Especially in the case of a multi-author blog, it can be really useful to include a logout link on your theme. In this recipe, I’ll show you how to do this easily. Only suitable for WordPress 2.7.

To create a "Logout" link on your WordPress blog, simply paste the following code on your theme:

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

Please note that this will work with WordPress 2.7+ only. If you haven't switched to WP 2.7 yet, the following code will do (almost) the same job:

<a href="/wp-login.php?action=logout">logout</a>

Related Posts

Related Posts

No related posts.

8 Responses

Jan 06 2009 20:45

Effectivement, j’avais remarqué qu’avec la nouvelle version de WordPress, la 2.7, la partie administration est d’autant plus sécurisée donc il s’est rajouté un wpnonce= à la fin du lien logout :)

Jan 06 2009 23:30

Now, will that link only show up when you are logged in?

Jan 06 2009 23:47

@Alison:
To make sure the link only show up when you’re logged in, proceed that way:

<?php if (is_user_logged_in()){
// the link goes here
} ?>

Jan 07 2009 10:18

I have a question, wp_logout_url() will work with WordPress 2.7+ only, prior to WP 2.7 use logout. How to make them compatible with any version? can we make conditional statement?

Jan 08 2009 11:12

Hello JB,
is it possibile to use the function and to apply a personalized anchor text to that?

Jan 10 2009 15:04

Very helpful tip for those who are not having any meta widgets active or wish to have a handy logout link at the bottom on the footer or so :p

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required