Adding a Logout Link to Your WordPress Theme, Plugin or Widget
by Emiliano Jankowski on September 20, 2011. Posted under:
Blog,
WordPress.
We have been chatting about various changes that make your WordPress site more useful for your viewers. Today, we will look at adding a custom logout link into your theme or plugin, so users can close their sessions.
This is not complicated. Lets see how to do it:
<pre lang=”php”>
<a href=”<?php echo wp_logout_url(); ?>”>Logout</a>
</pre>
If we want to show the logout link only when the user is logged in. We can do the following:
<pre lang=”php”>
<!–?php if (is_user_logged_in()):?–>
<a href=”<?php echo wp_logout_url(); ?>”>Logout</a>
<!–?php endif; ?–>
</pre>
WordPress is a powerful tool that becomes even more powerful with a few technical tweaks, like the one above. Do you have a favorite tweak for WordPress? Share with us in the comments.
Emiliano Jankowski is Senior Developer at Dinkum Interactive, specializing in creating elegant solutions to complex problems. Emiliano also leads Dinkum’s internal technology development projects, leveraging expertise with WordPress and CodeIgniter despite ten years experience in ASP and .NET. Emiliano is an avid scuba diver and lives in both Barcelona and Buenos Aires.