Magento Themes and Magento Extensions

Magento: How to check if current page is homepage

Share

Magento: How to check if current page is homepage

If you are checking in header.phtml then this will work for you :

if($this->getIsHomePage()) {
echo ‘Homepage!’;
} else {
echo ‘NOT in Homepage!’;
}
here is an alternative way to check for homepage( works in all .phtml files.):->

$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton(‘cms/page’)->getIdentifier();
if($routeName == ‘cms’ && ($identifier == ‘home’ || $identifier == ”)) {
echo ‘Homepage!’;
} else {
echo ‘NOT in Homepage!’;
}

Comments are closed.