How to check for home page in Magento

Sometimes there is a need to place a check in the PHTML file in order to show/run a specific code on the home page only. The following piece of code will do just that. It will check whether the page is actually the home page or just another page on the website.

$page = Mage::app()->getFrontController()->getRequest()->getRouteName();
$homepage = '';
if ($page == 'cms'):
	$homepage = Mage::getSingleton('cms/page')->getIdentifier();
endif;                    
						
if ($homepage == 'home') {

  // This code will only show on the home page

} 
else {

 // This code will show on all pages except for home page

}
Please follow and like us:
error

Be the first to comment

Leave a Reply

Your email address will not be published.