0

This question already has an answer here:

I am trying to use this code, found here, in the header.phtml file on my Magento 1.9.x website. For some reason, even on the home page at .com/ or .com/?SID= it is still applying H3 where it should be H1.

Does anyone know why this might be happening? Do I need other info on the page?

<?php if ($this->getIsHomePage()):?>
  <h1 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h1>
  <?php else: ?>
  <h3 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h3>
  <?php endif ?>

This code is also running to test against false positives - This code works but is only doing an echo on the code, not actually rendering it to provide the alt text:

<div id="are-we-home" style="display: none; ">
  <?php if($routeName == 'cms' && $identifier == 'home') { echo 'You are in Homepage!'; } else { echo 'You are NOT in Homepage!'; } ?>
</div>

marked as duplicate by Rakesh Jesadiya, Raphael at Digital Pianism, Rajeev K Tomy, Amit Bera, Keyul Shah Sep 16 '16 at 9:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

It's a bug. I think you're getting bitten by the same issue this guy is: 'Is home page' condition with different store views in magento not working

Replace your homepage check with this:

<?php 
  $action = Mage::app()->getFrontController()->getAction()->getFullActionName();
  if ($action == 'cms_index_index'):
?>

  <h1 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h1>

<?php else: ?>

  <h3 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h3>

<?php endif; ?>
  • This looks great for basic text, but how do I have PHP render inside of it? <h1 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h1> – Steven J Sep 15 '16 at 19:22
  • I edited my answer to include your code - It's an H1 on the home page, and h3 on every other page – SamC Sep 15 '16 at 19:43
  • Thanks! I think there's a ? missing on the closing php endif - got an error when trying to wrap in a DIV. I'm also getting the error Parse error: syntax error, unexpected '=' when trying to load this code. It's referring to this line <h1 class="logo"><strong><?php echo $this->getLogoAlt(); ?></strong></h1> – Steven J Sep 15 '16 at 19:46
  • ack - typo: missed the $ on $action in the first statement. and the last line should have a ? at the beginning and end: <?php endif; ?>. updated. – SamC Sep 15 '16 at 20:02
  • Looks like those edits fix it all. I'm seeing the logo alt text change between h1 and h3 like desired. Thanks so much! – Steven J Sep 15 '16 at 20:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.