In this post I am going to explain How to Identify Current Page Type in Magento 2.

Sometimes when you are working on custom development in Magento 2 then, you need to know what the current type of page being viewed is.

You can identify whether the current page is a category page, product page, checkout page, the home page, or CMS page. You can also customize or add the functionalities based on the current page.

Using below code snippet you can get current page type.

Add below code snippet in Block class.

Add below code snippet in template file.

That’s it. Enjoy Magento 2!!

Check this Best Magento 2 Tutorial.

Thank You.