Change any page title in Magento
1 Comment 27th OCT 2009 | Posted by Ivan Weiler in Magento

Here’s a quicky one
How do you change page title of every Magento page if some titles are hardcoded into controller?
Since some controllers in Magento likes to force page titles like
$this->loadLayout();
...
$this->getLayout()->getBlock('head')->setTitle($this->__('My Account'));
$this->renderLayout();
we can’t go with setTitle through layout, since controller is setting title right before rendering.
There is a simple solution for this, use another variable for title display
In page/html/head.phtml template replace default
<title>< ?php echo $this->getTitle() ?></title>
with
<title>
< ?php echo ($this->getForcedTitle()) ? Mage::getStoreConfig('design/head/title_prefix').' '.$this->getForcedTitle().' '.Mage::getStoreConfig('design/head/title_suffix') : $this->getTitle() ?>
</title>
or if you don’t wish to use title prefix/sufix added from Magento admin, simply with
<title> < ?php echo ($this->getForcedTitle()) ? $this->getForcedTitle() : $this->getTitle() ?> </title>
and now just set “forced” title for pages through layout files
<reference name="head"> <action method="setForcedTitle"><title>Account Dashboard</title></action> </reference>
Example for My Account page in layout/customer.xml:
<customer_account>
<reference name="head">
<action method=”setForcedTitle”><title>Account Dashboard</title></action>
</reference>
…
</customer_account>

















November 4th, 2009 at 23:17
Great Post! Thanks!
I’d like to add as a sufix, the special price in products pages only, would you have an idea for this?
Cheers