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

 

with

 

or if you don’t wish to use title prefix/sufix added from Magento admin, simply with

 

and now just set “forced” title for pages through layout files

 

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>

πŸ˜‰

You made it all the way down here so you must have enjoyed this post! You may also like:

Build your 2017 Magento SEO strategy with these tips Ivona Namjesnik
Ivona Namjesnik, | 10

Build your 2017 Magento SEO strategy with these tips

Free eCommerce SEO consultations by Inchoo at Meet Magento Poland Tea Pisac Benes
Tea Pisac Benes, | 0

Free eCommerce SEO consultations by Inchoo at Meet Magento Poland

In SERP title tags no longer control what’s shown Toni Anicic
Toni Anicic, | 10

In SERP title tags no longer control what’s shown

33 comments

  1. A bit confused. Looking for a way to change titles and meta description in pages like “Returns”, “Advanced search”. Now it is the same as on the homepage, how do I add the ones that I need? Didn’t quite get thing with xml.

    1. I am having a strange problem. Whenever I enter a default page title in my configuration, this title gets used for all these pages:
      – Login
      – Register
      – Search Results
      – Advanced Search
      – Wishlist
      – Sitemap
      – Addressbook
      – Applications
      – Logout
      – Forgot password

      If I remove the default title, the correct title is being used, however some pages (Forgot Password, Logout for example) will be missing a title completely. I am aware this issue is not present on a default 1.9.2.1 installation, I am hoping somebody knows what can cause this behavior. Thanks!

  2. Alternatively, you can keep the

    <title><?php echo $this->getTitle() ?></title>

    and just add this block at the top of the head.phtml page –

    if ($this->getForcedTitle()) {
        $this->setTitle($this->getForcedTitle());
    }
  3. To translate this title just add

     translate="title"

    to xml and it should looks like:

    <action method="setForcedTitle" translate="title"><title>Account Dashboard</title></action>
  4. Ok,but what if i want to insert in the title a filter that has been selected in the layer navigation ?

  5. Just tried this method and it worked. However, it changed titles of all of my pages to the one I’ve typed in XML. Not complete solution πŸ™

  6. This is great. However, I’m looking for a way to add the Short Description after the Product Name to the page titles on product pages. For this site, the Short Descriptions are very short and needed to differentiate similarly named products.

  7. What about forcing title directly from a phtml page? Im trying to get dynamic page titles working.

  8. Hi,

    This works very well for me. Thanks a lot.

    However I was wondering how does the setForcedTitle function work. I could not find any equivalent function.

    In which case can I use setForcedDescription for changing the meta description of a page.

  9. Hi you all,

    I am a fresher with Magento :), struggling finding a

    way to edit the title tags and description tags in just

    some pages (not products pages) but I just can’t find

    them in the backend.

    Please help?

    Thank you guys

  10. Nice Tip. Here is another way to set forced title without change any file.

    To set β€œforced” title for pages you can do this in the magento backend. Go to CMS/Pages and choose your page, then in the Design tab put the code in the field “Layout Update XML”. Save and refresh the cash.

    Of course, first you need to do the first step in this post (change the file In page/html/head.phtml)

    Regards.

  11. It works here, thanks!
    But how about changing the titles of Review pages (dynamically)?
    i.e. “{Productname} Review”
    Seen a couple of solutions but those didn’t work out.

    I hope someone can help me out on this problem.

    Thanks in advance!

  12. Thanks …
    This is very useful …

    Overall this site is good … site having very useful tips & Hints ….

    Keep Rokin……….

  13. 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 Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.