How to get default website id in Magento 2?

For Multi website setup of Magento e-commerce site, Sometimes need to get Default Website id using programmatically, You need to refer below code snippet for getting default website id.

Hope, You are aware of how to get website collection and other details using coding.
Create Block file,

Call from template file or PHP file,

echo $this->getDefaultWebsiteId(); // output is your default website code.
For single website output is 1.

Leave a Reply

Your email address will not be published. Required fields are marked *