How to Get Current URL in Magento 2

Magento 2 is a flexible and feature-rich eCommerce platform with many different functionalities that allows customizing your online store as per the business requirements!

Customizing the admin panel and frontend is easily possible using different tactics. While running an online store, there may be a system requirement to automatically get the current URL in Magento 2.

Facilitates admin by making their work easier as they do not have to find and type URLs when developing a page or attaching the URLs anywhere. In such a scenario, use the below solution to get the current URL in Magento 2.

Steps to Get Current URL in Magento 2

Create a block in the Vendor\Module\Block path.

Create block in Vendor\Module\view\frontend\templates path.

That’s it.

If you have any doubts regarding this post, just mention them in the comments section below.

I would be happy to help.

Feel free to share the solution with the Magento community via social media.

Thank You.

(based on 5 Reviews)
How to Get Current URL in Magento 2

Ronak Bhatti

Ronak is a Magento Developer at Meetanshi. He loves playing cricket. Apart from the work, he is an enthusiastic person who loves learning new skills.

Leave a Reply

Your email address will not be published.