$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category

I have a debug got the null value

  • where are you calling this code? – Philipp Sander Feb 19 at 7:59
  • Under the plugin folder call the Current category function @PhilippSander – Masud Shaikh Feb 19 at 8:04
  • Any option for category on/off – Masud Shaikh Feb 19 at 8:05
  • Category page is working but category search page is not working. When i debugged then got the error in code current category null. @PhilippSander – Masud Shaikh Feb 19 at 8:06
  • plugin for what file/method? – Philipp Sander Feb 19 at 8:07

Use this instead the object manager:

protected $_registry;

public function __construct(
    \Magento\Framework\Registry $registry
) {
    $this->_registry = $registry;

Then you call it like this :

$category = $this->_registry->registry('current_category');

$categoryId = $category->getId();

  • I have called same function. got the null value. – Masud Shaikh Feb 19 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.