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:
1 2 3 4 5 | if($this->getIsHomePage()) { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } |
If you are elsewhere (in any other .phtml template file or in any other .php class file) then you can use the following code:
1 2 3 4 5 | if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } |
Below is an alternative way to check for homepage:-
1 2 3 4 5 6 7 8 | $routeName = Mage::app()->getRequest()->getRouteName(); $identifier = Mage::getSingleton('cms/page')->getIdentifier(); if($routeName == 'cms' && $identifier == 'home') { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } |
Hope this helps. Thanks.





Mukesh Chapagain is a graduate of Kathmandu University (Dhulikhel, Nepal) from where he holds a Masters degree in Computer Engineering. Mukesh is a passionate web developer who has keen interest in open source technologies, programming & blogging.