How To Check If Current Page Is Homepage In Magento?

dev.png

In this article, I am going to explain the basic code for Magento through which we can identify the page on which we have. If we like some js, CSS or image files need to be loaded on the home page only. Of course, we can achieve this by XML file in Magento but the thing is below conditions will be useful when we really need it.

Below are the two ways that can be used in .phtml files.

One way :

if($this->getIsHomePage()) {
echo ‘This is Home Page!’;
} else {
echo ‘This is not Home Page!’;
}

Another way:

$routeName = Mage::app()->getRequest()->getRouteName(); 
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
 
if($routeName == 'cms'  &&  $identifier == 'home') {
echo ‘This is Home Page!’;
} else {
echo ‘This is not Home Page!’;
}

Visit us at Developergang to submit guest post related Technology + Write For Us + Guest Post