How to Check if Current Page is Homepage in Magento.?

Magento Check Current Page Is Homepage Or not

If you are looking to solve whether the current page is Home page in Magento or not then use the below given code to solve this issue with right code now.


Method 1 :- Magento Check Current Page Is Homepage Or not

Use the below code to find the home page status –
Step 1:-

<?php 

if($this->getIsHomePage()) {
	echo 'Welcome! it is a Homepage!';
} else {
	echo 'It is NOT in Homepage!';
}

?>

Method 2

If you are in template/page/html/header.phtml template file then you can check for homepage with the following code:

<?php 
if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()) {
  echo 'Welcome! it is a Homepage!';
 } 
else { echo 'It is NOT in Homepage!'; 
}

?>

Method 3
<?php 
$routeName = Mage::app()->getRequest()->getRouteName(); 
$pageidentifier = Mage::getSingleton('cms/page')->getIdentifier();
 
if($route == 'cms' && $pageidentifier == 'home') {
   echo 'Welcome! it is a Homepage!';
} 
else { echo 'It is NOT in Homepage!'; 
}
?>

Enjoy learning code in Magento!!!


You may also like...

Leave a Reply

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