Recently Added
Most Popular
Add a Login AND Logout Menu Item
- Date Added:
- Thursday, 05 November 2009
- Last Revised:
- Thursday, 05 November 2009
Item Details
We all know that Joomla's core User Login menu item works great when people see the words "Login", but then once the user is logged into the website, they are still greeted by the words "Login" instead of "Logout". For some this is not a big deal, but for most sites this is just a hassle.
Below I will show one of the ways to accomplish a successful Login & Logout menu item display.
Note: this method requires PHP and HTML (and some CSS for styling) knowledge. It also requires that you have access to your template's index.php file.
Step 1: The Login Link
This code can be inserted directly into your template's index.php file, in the location you wish to have the Login/Logout links appear.
<!--login link-->
<div id="loginlink">
<a href="http://www.yoursite.com/index.php?option=com_user&view=login">Login</a>
</div>
<!--end login link-->
Step 2: Getting the User's Status
Now, we want to add a bit of user interactivity. In order to do that we first need to get the user's name (or username) with a JFactory call and store it in a variable. We place that in the a PHP section of the template.
<?php
$username =& JFactory::getUser();
?>
Step 3: Showing the "Logout" Link
Then we can use the JFactory call to greet the users if they are logged in and also provide our coveted Logout link for them.
<?php
$username =& JFactory::getUser();
if ($username->guest) {
echo 'Hello, Guest. <a href="'. $this->baseurl .'index.php?option=com_user&view=login">Login</a>';
}
else {
$name = $username->get('name');
echo 'Welcome back, ' . $name . '. <a href="'. $this->baseurl .'index.php?option=com_user&view=logout">Logout</a>';
}
?>
Like I mentioned above, this is just one of many ways to show your logged in users the Logout link. Other methods include duplicating the Main Menu (or whatever menu it is that your Login link appears) module and playing with the permissions. I also hear there is a third-party addon that will handle the issue, but my search for it came up negative.








