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

  • author-img Nidhi Arora
  • 5 years
  • 351 views
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

    1250 Pittsford Victor Road Ste 310
    Pittsford, NY 14534

    Development Center

    Plot no. 10, Rajiv Gandhi
    Chandigarh Technology Park