Friday , May 26 2017
Home >> Magento theme tutorial >> Magento theme tutorial 1.8: Changing a page title

Magento theme tutorial 1.8: Changing a page title

In the previous chapter, we added some CSS and JavaScript files to the <head> tag of the HTML. To change the page title, we have to do it in a similar way.

We will change the page title of the contacts page that is available at http://magentodev.local/contacts.

Let’s start:

 

To change the page title of the contacts page, have a look at the following steps:

1. Go to the contacts page in the frontend. This is available at http://magento-dev. local/contacts.

2. You see that the page title reads Contact Us. We will change this to Give us a message.

3. Copy the layout/contacts.xml file from the base theme to our theme and open  the file. In this file, there is an xml tag <contacts_index_index>:

<contacts_index_index translate="label">
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contacts">
<title>Contacts Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns
right.phtml</template></action>
<action method="setHeaderTitle" translate="title"
module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm"
template="contacts/form.phtml"/>
</reference>
</contacts_index_index>

 

4. In the <reference name=”head”> tag, you will see a setTitle method. Set this line as follows:

<action method="setTitle" translate="title"

module="contacts"><title>Give us a message</title></action>

5. Clear your cache and reload the page. The title in your browser is now changed to

Give us a message.

How it works…

The <title> tag in the HTML page is in the head section. This head section is generated by the Magento head block.

In the template file, the code looks as follows:

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

This means that Magento will print the title of that object in the tag. To set the title of that object, we use the set Title function.

—————————————————————————————————————————————-

MOST WANTED OFFER!

BLACK FRIDAY SALE! 15% OFF ENTIRE STORE (until Nov 30)

BlackFridayBannerOnInventory


Ready to foster your knowledge with MAGENTO 2 BASIC GUIDE

The new Order Success combo with Magento 2 Inventory Management, Magento 2 Order Fulfillment, Magento 2 Dropship, Magento 2 Barcode Management and Magento 2 Purchase Management

Is your site still a mess and Magento extensions are not enough to save your site? Save your site with Magento Web Development Services now

magento services


About admin admin