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 Comments

Polychrome  on June 28th, 2010

215

Very handy thanks a lot

leaf  on July 16th, 2010

221

Great, it’s helpful for me!

vignesh  on September 29th, 2010

243

This function not working inside the top.phtml

Daniel Camargo  on September 29th, 2010

244

Thanks dude, it saves my life.

=)

nikhil  on October 12th, 2010

249

thanks budy i was finding from many time

vignesh  on October 20th, 2010

250

this function working in header.phtml in magento 1.3 only.. it is not work in latest magento 1.4.1

salik  on November 1st, 2010

251

Thanks buddy…

ecommerce web design  on January 22nd, 2011

261

Give more details about this blog for subscribe. Thanks for this blog.

Jonas  on February 12th, 2011

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?

Hanan Ali  on February 18th, 2011

266

Thanks for script :) its helpful

Praveen  on February 18th, 2011

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?

Golive  on October 4th, 2011

412

Does not work in Magento 1.5. Do you have an update on this? Would be great!!

Chetaru  on November 2nd, 2011

417

Thanks for sharing this information and resources its really help full for me with the help of this we can improve our magento working.
Web Design Company India

Arvind Bhardwaj  on November 3rd, 2011

419

Very nice trick.
Thanks:)

Leave a Comment

*

Spam protection by WP Captcha-Free