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!
- Contact Email
- [email protected]
- Issued By
- Envision eCommerce
- Country
- India
- Categories
- Software · Technology · Web Development
- Last Updated
- March 8, 2021
Disclaimer: This press release was submitted by a registered PRFree contributor and has not been verified or endorsed by PRFree. PRFree assumes no responsibility or liability for its accuracy, content, legality, or reliability. The contact email for this release can be viewed here. See our Disclaimer.