How to add login link beside welcome message in magento 1.7

How to add login link beside welcome message in magento 1.7

August 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to add login link beside welcome message in magento 1.7

As an experienced Magento developer, I often receive requests from clients who want to customize their storefront layout. A common requirement is moving the “login” link beside the default welcome message. In this post, we’ll walk through a step-by-step guide on how to achieve this in Magento 1.7.

Understanding the Current Setup

The current implementation uses PHP code and the customer session to display the welcome message dynamically. The html/header.phtml file is responsible for rendering the header section of your storefront, which includes the welcome message and additional HTML content.

<p class="welcome-msg">
   <?php echo $this->__('Hi %s', Mage::getSingleton('customer/session')->getCustomer()->getFirstname()); ?>
   <?php echo $this->getAdditionalHtml() ?>
</p>

This code snippet checks if a customer is logged in. If so, it displays the welcome message with their first name. Otherwise, it simply shows the default “Welcome” message.

To move the login link beside the welcome message, we need to modify the html/block.phtml file located at:

/app/design/frontend/{package}/{theme}/template/page/html/toplinks/block.phtml

In this file, look for the following line that contains the login link:

<a href="<?php echo $this->getUrl('customer/account/login') ?>"><?php echo $this->__('Login') ?></a>

Modifying the Welcome Message

Now let’s modify the html/block.phtml file to include the welcome message and the login link together.

  1. Find the container for the top links in your page layout XML file (app/design/frontend/{package}/{theme}/layout/page.xml). It should look something like this:
<block type="page/html_toplinks" name="top.links">
    <action method="addLink" translate="label">
        <label>Home</label>
        <url helper="catalog/getHomeUrl"/>
    </action>
    <!-- Add more links here -->
</block>
  1. Modify the top links block to include a new action for the welcome message and login link:
<block type="page/html_toplinks" name="top.links">
    <action method="addLink" translate="label" template="page/html/hello.phtml"><!-- New action -->
        <label>Welcome</label>
        <url helper="customer/getLoginUrl"/>
    </action>

    <!-- Other links remain the same -->
</block>

This new action calls a custom template page/html/hello.phtml to display the welcome message and login link. Let’s create this file next.

  1. Create a new file named hello.phtml in the following directory:
/app/design/frontend/{package}/{theme}/template/page/html
  1. Add the following PHP code to the newly created hello.phtml file:
<?php if (!Mage::getSingleton('customer/session')->isLoggedIn()): ?>
    <a href="<?php echo $this->getUrl('customer/account/login') ?>"><?php echo $this->__('Login') ?></a>
    <?php echo $this->__('Hi %s', Mage::getSingleton('customer/session')->getCustomer()->getFirstname()) ?>
<?php else: ?>
    <p class="welcome-msg">
        <?php echo $this->__('Hi %s', Mage::getSingleton('customer/session')->getCustomer()->getFirstname()) ?>
    </p>
<?php endif; ?>

This code checks if a customer is logged in. If not, it displays the “Login” link followed by the welcome message with their first name. If they are already logged in, it simply shows the default welcome message.

Clearing Cache

After making these changes, don’t forget to clear the cache to see the updated layout:

  1. Log in to your Magento admin panel.
  2. Navigate to “System” > “Cache Management” under the “Advanced” menu.
  3. Select all cache types and click “Flush Cache(s)” at the top right corner.

Conclusion

In this post, we explored how to move the login link beside the welcome message in Magento 1.7. By modifying the relevant layout XML file and creating a custom template, we were able to achieve the desired layout change while keeping the code clean and maintainable.

Remember that Magend has some great resources for learning more about Magento development. You can find detailed guides on their official documentation at https://docs.magento.com/m1/ (external link).

Don’t hesitate to reach out if you have any questions or need further assistance with your Magento storefront customizations.

Magento 1 Themes Customers CLI

Our network