Search This Blog

Jul 22, 2011

Magento: How to Check if current page is Homepage?

There are some instances that we need to add scripts, images or snippets in a specific page like “homepage”. In Magento, in order for you to check the current page if you are in home page / index page of your site, the following code work perfectly.
<?php if(
Mage::getSingleton('cms/page')->getIdentifier() == 'home'  &&
Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' 
) : ? >

//insert your code here 

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


4 comments:

Mika; said...

God, I feel like I should be taking notes! Great work

modra ideja said...

Great, exactly what i needed!

MOHIT KUMAR ARORA said...

Thanks.. I got exactly what I needed..

Rookie said...

Thanks mate! Works like charm!