How to set meta title, keywords, description and page title for a page programmatically in magento 2?

You can set Page Title and Page Browser Title separately using Magento 2.
If you want to set Different Page title and browser tab title you need to do using programmatically.

You can do it via Either Block prepareLayout() function or Controller execute() function.

You can set custom Page Title, Meta Title, Meta Description, Meta Keywords for any page using programmatically.

Priority of display Meta Title, Keywords, Description.
1. XML file
2. Block prepareLayout
3. Controller execute()
4. i18n
Priority with the highest number overrides the value of the lowest number from the above hierarchy.

if i18n CSV file has translation keywords available, All the old keywords from, whether XML, Block or Controller, override with  i18n CSV file.

For Set Page title and Page Browser title using Magento 2, Via Block File,

Using Controller,
Create Controller file in your module at Path, app/code/<PACKAGE_NAME>/<MODULE_NAME>/Controller/Controller.php

Using the above way you can set custom meta keywords, meta description, meta title, and Page H1 title.

Leave a Reply

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