Magento 2 set homepage

Today we discuss about Magento 2 set homepage.This tutorial include how to change or set homepage in system configuration program and how to change or set homepage from admin panel system configuration.There are two way to set home page one is from admin panel other is set homepage programmatically. So let start with our example

Set homepage from Admin Panel

Login to admin panel.

Store > Setting > configuration > Web Tab > Default Page

Select your desired page from dropdown.

Field CMS Home Page

Magento 2 set homepage

Set homepage from programmatically

Just inject the class \Magento\Config\Model\ResourceModel\Config $_resourceConfig and set value for web/default/cms_home_page to desired page ‘youridentifier’.

public function __construct(\Magento\Config\Model\ResourceModel\Config $_resourceConfig)
    {
        $this->_resourceConfig = $_resourceConfig;
    }

        $this->_resourceConfig->saveConfig('web/default/cms_home_page', 'youridentifier', 'default', 0);

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

Leave a Reply