How to Verify Theme Activation in Magento 2:-
Hello magento friends in this blog post i'm share with you to How to Verify Theme Activation in Magento 2 using 3 Diffrent Solution. In Magento 2, you can check the currently active theme by looking at the configuration settings and inspecting the database. Here's how you can do it:
➤(1st Method) : Verify Theme Activation By Admin Panel :
Log in to your Magento 2 admin panel.
- Go to Content > Design > Configuration.
- Select the store view for which you want to check the active theme.
- In the Applied Theme column, you'll see the currently active theme for that store view.
➤ (2nd Method) :Verify Theme Activation By Database in magento2:
You can also directly inspect the database to find the active theme.
- Access your Magento database using a tool like phpMyAdmin or command line.
- Locate the core_config_data table.
- Run the following SQL query:
By sql code:
SELECT * FROM core_config_data WHERE path = 'design/theme/theme_id';
This query will give you the active theme's theme_id and value (usually the theme's path).
Please note that the path 'design/theme/theme_id' might slightly vary depending on your Magento setup or version. If you encounter any difficulties, refer to the Magento documentation or community resources for specific guidance related to your Magento version.
In this case Remember that making changes to your database can have unintended consequences, so proceed with caution and consider taking a backup before making any modifications.
➤ (3rd Method) :Verify Theme Activation By Programmatic in magento2:
You can also check the active theme programmatically within your custom code, such as in a module or a custom script.
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
// Set up the bootstrap and initialize the application
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
// Get the theme model
$themeModel = $objectManager->get(\Magento\Framework\View\Design\ThemeInterface::class);
// Get the active theme
$activeTheme = $themeModel->getById($themeModel->getDesignThemeId());
// Check if the theme is active
if ($activeTheme->getArea() == 'frontend' && $activeTheme->getThemePath() != 'Magento/blank') {
echo "Active Theme: " . $activeTheme->getCode();
} else {
echo "No active theme found.";
}
Replace __DIR__ . '/app/bootstrap.php' with the actual path to your Magento 2's bootstrap.php file.
In this code snippet, we're using the Object Manager to retrieve the active theme and then checking if the active theme is a frontend theme and not the default Magento/blank theme.
In this case Please note that the specifics might vary depending on your Magento 2 version and any customizations you've made. Always ensure you're working with the right classes and namespaces based on your project's configuration.