Add Meta Tags for Contact page

As is well known, the contact page in Magento 2 is not handled like the other CMS pages. It comes from the module Magento_Contact. By default the contact page takes the default store's meta data for the tags description and keywords.

Below you can see how you can configure the default meta data for your store in Magento 2.1 CE.

Navigate to Magento admin under Content → Design → Configuration.

Select the Default Store View.

Click the tab HTML Head and add a Default Description and Default Keywords.

To change now the meta data of the Contact page so it will not take the default of your store, we have to modify the contact's page layout.

You can find the default contact's page layout under /vendor/magento/module-contact/view/frontend/layout/contact_index_index.xml and it looks like the screen below.

Copy this file under your theme directory /app/design/frontend/<Vendor>/<theme>/Magento_Contact/layout/contact_index_index.xml. If you open this file, the name of the root tag is <page> and it contains two main tags, the <head> and the <body>. Remove the tag <body> and from the tag <head> remove the tag <title>. In case you want also to change the page title, leave the tag <title> there and just change the value.

To change now the meta tags description and keywords we have to add them inside the tag <head>, like you can see in the screen below.

Clean Magento Cache, refresh your Contact page and view the source code to see the new meta tag values.

Feel free to share this post and ask your questions in the comments below.

Till next time!