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();
if ($homepage == 'home') {

  // This code will only show on the home page

else {

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


Be the first to comment

Leave a Reply