Apply an Admin theme
What's in this topic
This topic describes how to apply your custom theme for Magento Admin.
Prerequisites
- Set your Magento application to the developer mode. The application mode influences the way static files are cached by Magento.
- Create a custom theme for the Admin panel.
- Add a new custom module or decide to use existing custom module. The module must load after the Magento_Theme module. To ensure this, add the following code in
<your_custom_module_dir>/etc/module.xml
(replace placeholders with your module information):
If you choose to create a separate dedicated module, you can use the Magento_SampleMinimal module from the Magento 2 sample modules repository as example of a minimal module you need. If you will copy and use Magento_SampleMinimal, do not forget to enter your vendor and module naming, instead the ones used in the sample, in the <your_module_dir>/etc/module.xml
, <your_module_dir>/registration.php
, and <your_module_dir>/composer.json
files .
If you decide to use the existing module, keep in mind, that theme declaring might be affected when the module is changed.
Apply a custom theme in Admin: Overview
To apply the Admin theme, take the following steps:
- Specify the new Admin theme in your module’s
di.xml
- Update the components by running the
bin/magento setup:upgrade
command. - Open the Admin in browser and view the new theme applied.
Each step is described further with more details.
Specify the custom Admin theme in di.xml
You need to specify the admin theme to be used in the <your_module_dir>/etc/adminhtml/di.xml
file. Add it, if the file does not yet exist in your module.
In <your_module_dir>/etc/adminhtml/di.xml
add the following (replace the placeholders with the vendor name and theme code of your Admin theme):
Update components to actually apply the Admin theme
For your changes to take effect, you need to update Magento components. For this,
run the bin/magento setup:upgrade
command in your command line. If prompted, also run bin/magento setup:di:compile
.
For details about performing command line tasks, view the following topics:
Open Admin in browser
The last step is to open the Admin in browser and view the new theme applied.