5

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?

6

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>
  • I'm having a similar issue and tried overriding in the local.xml file of my custom template but it didn't update the changes. Is there another step to using the XML option? – metame Feb 10 '16 at 16:57
  • Are you sure that your local.xml is loaded and that the category ID is correct? If in doubt, ask a new question. – Simon Feb 10 '16 at 17:40
  • Fairly new to magento, I will ask a new question just to make sure I didn't miss anything. – metame Feb 10 '16 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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