How to get the current category in Magento 2?

For getting the current category you can use the below code

<?php 
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
    echo $category->getId();
    echo $category->getName();
?>

Please leave your comment for asking any question or suggestion.

Need Help? How to get the current category in Magento 2?