Sometimes, even the seemingly easiest things are very complicated to in Joomla. One of these easy, yet complicated things to do, is creating a Logout menu item in Joomla. We had this request several times so we thought it would be helpful to share how to do it.
Note that the below applies to both Joomla 1.5 and Joomla 1.6.
Step 1 – Install Jumi
The first thing that you need to do is to install Jumi, an extension that allows you to have PHP code in your text (and will have that PHP code processed as well). Jumi is compatible with all versions of Joomla.
Step 2 – Create article
Create a new article (let’s call it “logout”) and paste the following code into a Jumi:
$return = base64_encode('http://www.example.com');
$url = JRoute::_('index.php?option=com_users&task=user.logout&' . JUtility::getToken() . '=1&return=' . $return);
header('Location: ' . $url);
Note: Swap ‘http://www.example.com’ with the URL that you would like users redirected to after log out.
Step 3 – Create menu item
Create a new menu item with a Menu Item Type of “Single Article” and select the “logout” article. You will also want to set the Access of this menu item to your Registered group or a similar group of logged in users so that only logged in users can see your logout link.
That’s it, you’re done! You now have a logout link in you menu!