🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Programmatically Get All Websites in Magento 2

By Jignesh ParmarUpdated on May 22, 2025 1 min read

Magento is a robust, scalable online platform used for selling online. Such an eCommerce platform supports the multi-website, multi-language and multi-store view. So, it is possible to build multiple websites, their stores and store view depending on the business requirements.

Are you a Magento 2 store admin handling multiple websites on the same platform?

When running an online store with multiple websites sometimes you may need to get the list of all the websites in Magento 2. Then, this solution will help you to programmatically get all websites in Magento 2.

Method to Programmatically Get All Websites in Magento 2: 

The method to get the list of all the websites in Magento 2 is as follows:

use Magento\Store\Model\ResourceModel\Website\CollectionFactory as WebsiteCollectionFactory;

protected $websiteCollectionFactory;

public function __construct(WebsiteCollectionFactory $websiteCollectionFactory)
{
$this->websiteCollectionFactory = $websiteCollectionFactory;
}

//get website collection
$websiteCollection = $this->websiteCollectionFactory->create();

That’s it.

Also, do not forget to share the solution with the Magento Community via social media.

Thank you.

Jignesh Parmar Full Image
Article byJignesh Parmar

An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.