How To Get All Category URLs in Magento 2

How To Get All Category URLs in Magento 2

Magento 2 store categories make it easy for the visitors to find the exact desired product quickly.

Here’s the programmatic solution to get all category URLs in Magento 2. With this solution, the admin can get the list of all categories URLs in the store and then use it in multiple ways according to the business requirements.

For example, you want to implement HTML sitemap in Magento 2 store. HTML sitemap is sort of a blueprint of the online store. It makes navigation easy. The admin can also use HTML sitemap to keep the track of all the URLs in the Magento 2 store. Using the below code, one can list the category URLs in the HTML sitemap.

Also, when the Magento 2 store gradually expands, the admin may want a handy list of category URLs while adding new or updating the existing categories.

In all such scenarios, use the below solution to get all categories URLs in Magento 2.

Steps to Get All Category URLs in Magento 2

  1. Use the below code in registration.php at app/code/Vendor/Module

  2. Create module.xml at app/code/Vendor/Module/etc/ and paste the below code.
  3. Create CategoryPageUrls.php at app/code/Vendor/Module/Helper/ and use the below code.

That’s it.

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

I would be happy to help.

Do not forget to share the solution with Magento Community via social media.

Thank You.

Related Posts:

  1. How to Create a New Root Category in Magento 2
  2. How to Get Categories From a Product in Magento 2

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

(based on 14 Reviews)

Yash is a Magento Developer at Meetanshi. He loves playing computer games and watching action movies. For brain exercise, he likes to play Chess.

Leave a reply:

Your email address will not be published.