I have a module in the vendor folder installed via Composer. I want to keep it enabled for my custom theme. But when a user selects the Luma theme, this module should be disabled.

My module depends on a theme, so it throws errors when I enable Luma. How can I handle this in Magento 2.4?

1 Answer 1


Add the below code to your module to check which is the current theme. and you can add conditions where specific to your theme then only your code is work

protected $themeProvider;

protected $scopeConfig;

protected $storeManager;

public function __construct(
    \Magento\Framework\View\Design\Theme\ThemeProviderInterface $themeProvider,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Magento\Store\Model\StoreManagerInterface $storeManager

) {
    $this->storeManager = $storeManager;
    $this->scopeConfig = $scopeConfig;
    $this->themeProvider = $themeProvider;

public function getCurentThemeData(\Magento\Framework\Event\Observer $observer)

    $themeId = $this->scopeConfig->getValue(

    return $this->themeProvider->getThemeById($themeId);

In Phtml file

$themeData = $block->getCurentThemeData();
echo "<pre>";
echo "</pre>";

if ($themeData->getCode() == 'YourThemeCode') {
    // code...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.