How To Check If The Current Area Is Frontend Or Backend In Magento 2

How To Check If The Current Area Is Frontend Or Backend In Magento 2

The Magento 2 store admin gets additional privileges for efficiently fulfilling their responsibility as a store admin.

For example, the admin gets the facility to use a particular shipping or payment method while placing an order from the backend.

However, to implement admin-exclusive features, you need to first check if the current area is frontend or backend in Magento 2. The method given below allows checking if it is frontend or backend.

Check the area of the current URL in Magento 2 with any of the two methods:

  1. With objectManager
  2. With class method

And, you get one of these outputs as frontend, adminhtml, or webapi_rest.

Method to check if the current area is frontend or backend in Magento 2:

  1. With objectManager

  2. With class method

That’s it.

Any doubts?

Mention them in the Comments section below. I’ll help you with the issue.

Do share the solution with fellow developers via social media.

Thank you.

5
(based on 5 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply