Get page title without prefix or suffix
-
16-10-2019 - |
Question
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!
Solution
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>
OTHER TIPS
Just access the _data-Array directly:
$this->getLayout()->getBlock('head')->getData('title');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange