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!