How to add an image instead of text 'My Cart' in top link - Magento

How to add an image instead of text 'My Cart' in top link - Magento

August 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to add an image instead of text 'My Cart' in top link - Magento

You’ve found yourself in a common situation where you want to replace the default “My Cart” text link in your Magento store’s top navigation with a custom image. The good news is, this is quite possible! In this post, we’ll walk through the steps required to achieve this.

Understanding the Default Behavior

By default, Magento renders the shopping cart link as plain text. The label is defined by the checkout/links.phtml template file located in your theme directory. If you’re using a custom theme, the file will be under app/design/frontend/<your_vendor>/<your_theme>/template/checkout/links.phtml.

Step 1: Locate and Edit the Template File

First, make sure you are editing the correct version of this file for your theme. The version under the current active theme directory should be edited.

Open the checkout/links.phtml file and locate this line:

<?php if ($this->getCartHelper()->getSummaryCount()): ?>
    <a href="<?php echo $this->getUrl('checkout/cart') ?>" class="top-link-cart"><?php echo $this->__('My Cart (%s)',$this->getCartHelper()->getSummaryCount()) ?></a>
<?php endif; ?>

Step 2: Add the Image Path

Now, let’s replace the text with the image path. Assuming your image is named cart.png and located in the images folder of your theme directory (i.e., app/design/frontend/<your_vendor>/<your_theme>/images), update the line as follows:

<?php if ($this->getCartHelper()->getSummaryCount()): ?>
    <a href="<?php echo $this->getUrl('checkout/cart') ?>" class="top-link-cart"><img src="<?php echo $this->getViewFileUrl('images/cart.png'); ?>" alt="My Cart" /></a>
<?php endif; ?>

Step 3: Update the CSS

Next, you need to style this image to make it look like a link and center it properly. You can do this by adding some custom CSS to your theme’s styles.css file (located in the same theme directory).

Add the following code:

.top-link-cart {
    display: inline-block;
    height: 30px; /* adjust as needed */
    width: auto;
    background-image: url('<?php echo $this->getViewFileUrl('images/cart.png'); ?>');
    background-repeat: no-repeat;
    text-indent: -9999px;
}

.top-link-cart:hover {
    opacity: 0.75;
}

Step 4: Refresh the Cache

After making these changes, make sure to flush your Magento cache for the new styles and template changes to take effect.

That’s it! Your “My Cart” link should now display as a custom image instead of text. This approach ensures that you aren’t losing any of the link functionality while adding visual appeal to your store’s top navigation.

Remember, if you’re using a child theme or have overridden this file elsewhere in your codebase, make sure to update those versions as well for consistency across your site.

Conclusion

Customizing the shopping cart link is a great way to enhance the user experience and branding of your Magento e-commerce website. By following these steps, you should now be able to easily replace the default text with an image of your choice.

If you’re looking to explore more advanced customizations or need assistance with other aspects of your Magento development, feel free to reach out to us at Laravel Company. We specialize in providing high-quality development services and support for e-commerce platforms like Magento.

Checkout Themes

Our network