How to change Magento 2 Sub Category Page Title? I want to show parent category title when visiting sub-category.

  • you can edit sub category and give custom meta title in search engine optimization tab Jul 10, 2017 at 8:07
  • not meta title. i mean the title that is called via $block->getPageHeading()
    – don
    Jul 10, 2017 at 8:25
  • Improve your question adding your code. You could change any category title from admin, so you just follow ManojDeswal answer.
    – LucScu
    Jul 10, 2017 at 9:34

2 Answers 2


You can try the below code.

Step1 - Creating registration.php file in the following path - app/code/Training/Changecattitle.

use Magento\Framework\Component\ComponentRegistrar;

Step2 - Creating module.xml file in the following path - app/code/Training/Changecattitle/etc.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <module name="Training_Changecattitle" setup_version="1.0.0">
            <module name="Magento_Catalog"/>

Step3 - Creating di.xml file to overwrite \Magento\Catalog\Block\Category\View in the following path - app/code/Training/Changecattitle/etc.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Block\Category\View" type="Training\Changecattitle\Block\Category\View" />

Step4 - Creating View.php file in the following path - app/code/Training/Changecattitle/Block/Category.

     * Copyright © 2016 Magento. All rights reserved.
     * See COPYING.txt for license details.
    namespace Training\Changecattitle\Block\Category;

     * Class View
     * @package Magento\Catalog\Block\Category
    class View extends \Magento\Catalog\Block\Category\View

        protected function _prepareLayout()


            $category = $this->getCurrentCategory();
            if ($category) {
                $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
 // Here you can set custom page title in your case you can get root category page title and set here.  

            return $this;


Run setup upgrade script.

Clear Cache.

Give folder permission 0777 to var folder.

you can download full module from github link https://github.com/jothibasuj/Mage2-Custom-Modules/tree/master/Mage2-Custom-Modules/Training/Changecattitle

  • you can check the above code. it is working for me. if you have any problem let me know.
    – Jjo
    Jul 10, 2017 at 10:36
  • Did you get the result?
    – Jjo
    Jul 10, 2017 at 11:47
  • Is the above code working for you or not?
    – Jjo
    Jul 12, 2017 at 10:43
  • this change the meta title i dont want to change the meta title any help Sep 25, 2019 at 14:07

You need to rewrite _prepareLayout function of Category/View.php


Here find the parent category of current category.

update below line accroding to your need


But parent categories can be more than one so you need to add your logic according to your need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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