How to identify the current page ?

Loading...
How to identify the current page ?

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$request = $objectManager->get('Magento\Framework\App\Action\Context')->getRequest();

if ($request->getFullActionName() == 'catalog_product_view') {

//you are on the product page

}

if ($request->getFullActionName() == 'catalog_category_view') {

//you are on the category page

}

if ($request->getFullActionName() == 'cms_index_index') {

//you are on the home page

}

if ($request->getFullActionName() == 'cms_page_view') {

//you are on the cms page

}

?>

Note : you can check for custom page also for that open inspect tab of page and then move to body tag at there see the given class from there you can get the action name convert dash ( - ) into underscore ( _ ) and then you are good to go , refer below given image



Copyright © 2024 Tridhya Tech Limited, Inc. All rights reserved.