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.
One Reply to “Adding a Logout Link to Your WordPress Theme, Plugin or Widget”
WHERE do you add this code, please?