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
1
2
3
4
|
$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
1
|
< title >< ? php echo $this->getTitle() ?></ title > |
with
1
2
3
|
< 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
1
2
3
|
< title > < ? php echo ($this->getForcedTitle()) ? $this->getForcedTitle() : $this->getTitle() ?> </ title > |
and now just set “forced” title for pages through layout files
1
2
3
|
< 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>