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. app/code/Chapagain/HelloWorld/Block/HelloWorld.php <?php namespace Chapagain\HelloWorld\Block; class HelloWorld extends \Magento\Framework\View\Element\Template { protected $_logo; … Read more

Magento: How to check if current page is homepage?

Here is a quick Magento code to check if the current page is homepage or not. If you are in template/page/html/header.phtml template file, then you can check for homepage with the following code: if($this->getIsHomePage()) { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } If you are elsewhere (in … Read more