How To Get Current Category Name in Magento 2

Magento 2 CMS is superior to other CMSs when it comes to customization. The platform allows us to customize and develop functionalities to cater to modern business requirements. In order to do so, the developer may need to perform custom solutions as shown in this post.
If you have any doubts regarding this post, just mention them in the Comments section below.

Steps to Get Current Category Name in Magento 2

  1. Use the below code in the CategoryBrand.php file at VendorModuleBlock.
  2. Use the below code in module_index_index.xml at Vendor/Module/view/frontend/layout.
  3. Add the below code in template_file.phtml at Vendor/Module/view/frontend/templates.

That’s all!
Simply, use the getCurrentCategory() in the file, wherever you need to get current category.
Never miss Magento tips, tricks, tutorials, and news.
For example, the store owner wants to offer discounts based on category. The store offers clothing as well as footwear but the discount is to be offered on the products from the footwear category only. To develop this functionality, one needs to get the category name of the landing page. In such a scenario, use the below solution to get current category name in Magento 2 store.
I would be happy to help.
Thank You.

Get Weekly Updates

Thank you for subscribing.

Something went wrong.
Feel free to share the solution with Magento Community via social media.




(based on 0 Reviews)