1

I want text in <h1> tag to match page title, but without store prefix.

I'm getting page title like so:

<h1>
    <?php echo $this->getLayout()->getBlock('head')->getTitle(); ?></h1>

How can I get page title without store prefix, or how can I retrieve store prefix option?

Thank you!

2

The quick and dirty way to do it.

To cut prefix:

<?php 
$prefix = Mage::getStoreConfig('design/head/title_prefix');
$title = $this->getLayout()->getBlock('head')->getTitle();
$processedTitle = trim(substr($title, strlen($prefix)));
?>
<h1><?php echo $processedTitle;?></h1>

To cut suffix:

<?php 
$suffix = Mage::getStoreConfig('design/head/title_suffix');
$title = $this->getLayout()->getBlock('head')->getTitle();
$processedTitle = substr($title, 0, strlen($suffix) * -1);
?>
<h1><?php echo $processedTitle;?></h1>
|improve this answer|||||
0

Just access the _data-Array directly:

$this->getLayout()->getBlock('head')->getData('title');
|improve this answer|||||
  • Returns the same result for me, with store title. – Marvin3 May 23 '13 at 16:07
  • 1
    yes, obviously. because the value of _data is changed. there is no way to get the original value back. – Fabian Blechschmidt May 23 '13 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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