How do I create a default category meta title for all the category pages?

I would like it to be something like this:

<title>{{category name}} - blah blah blah blah</title>

I want it to be the default only for category pages.

Is this possible?

3 Answers 3


Add the following code in your head.phtml

if (Mage::registry(current_category)) {
    echo '<title> Categoryname- keyword1 keyword2 keyword3"';


As far as I know Mage::registry('current_category') can be used to check whether we are in a category. See Alanstorm's Answer. The important parts of that answer is adding below for reference

Current versions of Magento register certain global variables (not PHP globals, but things global to the Magento system) on certain pages.

Calling the following

   $category = Mage::registry('current_category');         
   $product  = Mage::registry('current_product');
   $product  = Mage::registry('product');

will either return null if the objects haven't been set (i.e. you're on a page without a category or a product), or return category and product objects.

If a product object is returned you're on a product page.

If no product object is returned but a category object is, you're on a category page.

then you can print what you want.

  • seems to be true also on product pages. Commented Jul 6, 2015 at 5:53
  • Let me check and get back
    – Sundar
    Commented Jul 6, 2015 at 5:58
  • nope current_category register only works in category page. Commented Jul 6, 2015 at 6:04
  • weird it does not for me. however i found a way to get over it ( Mage::registry('current_product') ) Commented Jul 6, 2015 at 6:06
  • 1
    Sorry. Yar. I am not aware that.. Let me edit ma answer. :)
    – Sundar
    Commented Jul 6, 2015 at 6:38

The most cleaner way to perform this is by observing to the event controller_action_layout_generate_blocks_after. So the important parts of your module (Namespace_Module) would be

File : app\code\local\Namespace\Module\etc\config.xml


Here we are registering an observer to the event controller_action_layout_generate_blocks_after. This particular event will get triggered, after every blocks is generated from the layout. So at this particular time, we can access every blocks in the Layout. The block that we are interested here is head block (ie Mage_Page_Block_Html_Head). This block is holds the title element.

File : app\code\local\Namespace\Module\Model\Observer.php

class Namespace_Module_Model_Observer

    const CATEGORY_TITLE_CONSTANT = 'blah blah blah blah';

    public function setCategoryPageTitle(Varien_Event_Observer $observer)
        //ensure modification applies only for category page.
        if (Mage::registry('current_category')) {
            //get head block
            $head = $observer->getLayout()->getBlock('head');
            $title = $this->_prepareCategoryTitle();
            //set new title

    protected function _prepareCategoryTitle()
        return Mage::registry('current_category')->getName()
            . '-'
            . self::CATEGORY_TITLE_CONSTANT;

This is our observer class. The method that will alter category title is setCategoryPageTitle(). What this function does is simple. It ensures we are in a category page. Then it will grab the head block and set a new title. To set a new title, we are using a protected function _prepareCategoryTitle(). I defined this function according to this question's need. Currently it will return category name + blah blah blah. So you can alter this method and change the title according to your needs.

Note: Here NO CORE EDITS, NO ALTERNATION IN DEFAULT TEMPLATES. That is why this is the cleaner method.


Basically, title of pages from meta title field of category.

For your requirment,you need to rewrite class Mage_Catalog_Block_Category_View on there you need check current title using check Head block getTitle() value and reset it value to default when it does have any value.

Rewrite class:

class Dev_AmitCatalog_Block_Catalog_Category_View extends Mage_Catalog_Block_Category_View
   protected function _prepareLayout()


        if ($headBlock = $this->getLayout()->getBlock('head')) {
            $category = $this->getCurrentCategory();
    if (!$headBlock->getTitle()) {
                $headBlock->setTitle($category->getName().' - blah blah blah blah');


  • Where should the rewrite class be located? as I have put it in /Block/Catalog/Category/View.php in my extension folder but no joy
    – Goose84
    Commented Feb 11, 2016 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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