Tutorialsplane

Magento2 get current Category


Magento2 get current Category- In magento 2 the way to get the current category has been changed. You can use object manager to get the current category detail in magento2. Here in this tutorial we are going to explain how you can access the current category in magento 2.


Magento2 get current Category

You can get the current category detail in magento 2 using the object manager as below –

Magento2 get current Category :

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');
    echo $catId = $category->getId();
    //$catName = $category->getName();

The above example will give you the current category details. You can access other details same as we have shown the category id and name.