Display login and logout links from template file - Magento 1

In some special cases, we want to display login & logout links in some specific areas of our Magento themes. In such situations, we can use a simple code snippet on our template files.

<?php
//check the user is logged in or not
if (! Mage::getSingleton('customer/session')->isLoggedIn()){
	//if user logged on show the logout link
	echo "<a href="". Mage::helper('customer')->getLoginUrl() . "">" . "Login" . "</a>";
}
else{
	//if user is not logged on yet show the login link
	echo "<a href="". Mage::helper('customer')->getLogoutUrl() . "">" . "Logout" . "</a>";
}
?>

Recent Posts

  1. Replace string in multiple files - Command line
  2. Solve Grunt error - Port 35729 is already in use by another process
  3. Install WP-CLI
  4. Install LAMP - Apache2 , MariaDB, PHP 7 on Debian 8
  5. Enable / Disable Magento 2 module using command line


Questions / Comments

If you found this article interesting, found errors, or just want to discuss about them, please get in touch. Send an email to hello@sarathlal.com & I like your words.