Change any page title in Magento

1 Comment 27th OCT 2009 | Posted by Ivan Weiler in Magento

Change any page title 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>

;)

If you like what you read, please share it.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Reddit
  • Technorati
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Netvibes
  • FriendFeed
  • NewsVine
  • Sphinn
  • Tumblr

There are 1 comments (Add Yours +)

  • 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

Leave a Comment

Magento Design and Development | Magento SEO | iPhone Application Development Web Application Development with ZEND | WordPress Ecommerce | WordPress development
Sitemap

Inchoo - webappsolutions | 2009