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


Posted March 8, 2021 by EnvisioneCommerce

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!
-- END ---
Share Facebook Twitter
Print Friendly and PDF DisclaimerReport Abuse
Contact Email [email protected]
Issued By Envision eCommerce
Country India
Categories Software , Technology , Web Development
Last Updated March 8, 2021