Magento check current page is Homepage

The following code is used to check if the current page is homepage.

<?php if(
Mage::getSingleton('cms/page')->getIdentifier() == 'home'  &&
Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' 
) : ? >

The other way is to do the following way: works on 1.4.x

<?php
if($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))):
	echo "Homepage";
else:
	echo "Not in Homepage";
endif;
?>

Note: You can use “Mage::getUrl()” function where “$this” reference is not valid.

14 thoughts on “Magento check current page is Homepage

  1. 265

    Exactly what I was looking for… there was another suggestion with using $_SERVER['REQUEST_URI']. But this didn’t work. Magento just showed nothing at all. Does anyone know why this is?

  2. 267

    It was really a helpful stuff. I used the same method to get the inner page and to the needed changes which is applicable to specified page. Any code updation needed this code to work in magento 1.4.1?

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Spam protection by WP Captcha-Free