Assign custom theme programmatically to store in Magento 2

Today we discuss how to assign custom theme programmatically to store in Magento 2. Sometimes you need to set the theme programmatically. For that, you need theme_id and store_id. You can get theme_id from theme table.

use Magento\Framework\App\Config\ConfigResource\ConfigInterface;

/**
* @var ConfigInterface
*/

private $configInterface;
public function __construct(
ConfigInterface $configInterface
) {
$this->configInterface = $configInterface;
}

Following belowcode you can change theme programatically.

$this->configInterface->saveConfig('design/theme/theme_id', {{theme_id}}, 'stores', {{store_id}});

NOTE: change {{theme_id}} and {{store_id}} with your theme id and store id

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