Question

Is there a way to change the page title and meta description from a .pthml file ?

I know this is stuff regarding the header files but is there any way in magento to force to change the page title and add a meta description in the .pthml files? Or is this simply not possible?

Was it helpful?

Solution

This is not really possible. It is just possible in very few template files. The problem is, that Magento renders the template files hierarchically. Naturally, the head block where the title and the description are rendered, is rendered in the beginning of that process. You could update the information in general template files like 2columns-right.phtml if you insert the following before the call to $this->getChildHtml('head'):

<?php $this->getLayout()->getBlock('head')->setTitle('My title'); ?>
<?php $this->getLayout()->getBlock('head')->setDescription('My description'); ?>

Mind that this is very bad practice. But it may be interesting that it works. If you insert the above code in a template file which is rendered later, the title and description will not be updated (since they have already been rendered before).

Maybe you can use some layout handles and update the title/description via layout XML? Something like:

<CATEGORY_3>
    <reference name="head">
        <action method="setTitle">
            <title>My title</title>
        </action>
    </reference>
</CATEGORY_3>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top