How to Access Current Category ID in Magento 2 Using the Object Manager?

  • author-img Nidhi Arora
  • 7 years
How to Access Current Category ID in Magento 2 Using the Object Manager?

Object manager is now the more effective method to acquire the current category detail in Magento 2.

Read on to learn how to access current category ID in Magento 2:

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

The afore-shared example will provide you the current category details. You can access other details similar to what we have displayed the category id and name. Let our certified Magento experts know if you have any query.

Happy Magento 2 Coding!

Download Blog

ENQUIRY

Ready to Get Started

Communication is the key for us to understand each other. Allow us to understand
your requirements or queries. Present us with an opportunity to serve you.

Fill out the form and out team will get back to you
within 24 hours

    Head Office

    815 Brazos St STE 500, Austin,
    TX 78701, USA