Home » Magento, Magento 212 May 2016

Magento 2: Check if Current URL is Homepage

This article shows how we can check if the current page URL is homepage URL in Magento 2.

Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of Logo block class in the constructor of my module’s block class.


See more functions in vendor/magento/module-theme/Block/Html/Header/Logo.php.

Now, we use can the function in our template (.phtml) file.

You can write the following code at the bottom of your site’s index.php file and see the output at the bottom of your page when you are in homepage or in any other page:

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed