Step-by-Step Guide to Creating a Custom Admin Theme in Magento 2

Table of Contents

Creating a custom admin theme in Magento 2 is essential for businesses that want to improve their backend interface. A custom admin theme not only makes the admin panel more user-friendly but also aligns it with your company’s branding and workflow needs. By customizing the admin theme, you can enhance usability, making it easier for your team to navigate and manage the store efficiently. Additionally, a well-designed theme can boost functionality by adding features specific to your business requirements, keeping up with the latest Magento development trends.

This guide will walk you through the entire process of creating a custom admin theme in Magento 2. You’ll learn how to set up the theme structure, customize layouts and templates, add custom styles and JavaScript, and perform advanced customizations like modifying admin grids and forms. We’ll also cover testing, debugging, and deploying your theme, ensuring you have a complete understanding of the process from start to finish. If you prefer professional assistance, consider hiring Magento developers to ensure your project is handled expertly and efficiently.

1. Prerequisites and Setup

1.1 Required Knowledge and Tools

  • Basic Understanding of Magento 2 Architecture: It’s important to have a general idea of how Magento 2 is structured and operates. This includes knowing how themes and modules interact within the system. If you are still using Magento 1.x and looking to upgrade to Magento 2, you can read our guide on migrating from Magento 1 to Magento 2.
  • Familiarity with PHP, HTML, CSS, and JavaScript: You’ll need to know these programming languages because they are essential for customizing and creating themes in Magento 2. PHP is used for backend development, HTML and CSS for front-end layout and styling, and JavaScript for interactive features.
  • Tools:
    • Code Editor: A good code editor like Visual Studio Code, Sublime Text, or PHPStorm will make writing and editing your code much easier.
    • Magento 2 Installed: Ensure you have Magento 2 set up and running. This can be on a local server or a development server.
    • Access to the Admin Panel: You’ll need admin panel access to test and apply your custom theme.

1.2 Setting Up the Development Environment

  • Installing and Configuring Magento 2: Download Magento 2 from the official website and follow the installation instructions. Make sure to configure it properly with your database and server settings.
  • Setting Up a Local Development Environment:
    • XAMPP/MAMP: These are tools that create a local server environment on your computer. They include Apache, MySQL, and PHP, which are necessary for running Magento 2.
    • Docker: Docker can create isolated containers for your development environment, making it easy to manage dependencies and versions.

By ensuring you have the right knowledge, tools, and environment setup, you’re well-prepared to start creating a custom admin theme in Magento 2. This foundation will make the development process smoother and more efficient.

2. Understanding Magento 2 Theme Structure

2.1 Magento 2 Theme Hierarchy

  • Explanation of the Theme Fallback Mechanism: Magento 2 uses a fallback mechanism to determine which theme files to use. If a file isn’t found in the custom theme, Magento will look for it in the parent theme. If it’s not there either, Magento will use the default base theme file. This ensures that the website always has the necessary files to function properly.
  • Difference Between Frontend and Backend Themes:
    • Frontend Themes: These are the themes that customers see when they visit your website. They control the look and feel of the online store.
    • Backend (Admin) Themes: These are the themes used by administrators to manage the store. They control the appearance and layout of the admin panel, making it easier for store managers to navigate and perform their tasks.

2.2 Admin Theme Directory Structure

  • Overview of the Magento 2 Admin Theme Directory Structure: The directory structure of a Magento 2 admin theme is organized to keep different types of files separate and easy to manage. Here’s a look at the key components:
  • Key Files and Directories:
    • theme.xml: This file defines the theme’s name, parent theme (if any), and other metadata. It tells Magento how to handle the theme.
    • registration.php: This file registers the theme with Magento. It’s necessary for Magento to recognize and apply the theme.
    • web: This directory contains all the static files such as CSS, JavaScript, and images. These files are used to style and add functionality to the theme.
    • layout: This directory holds XML files that define the structure of pages in the admin panel. These files control how different blocks of content are arranged on the page.
    • templates: This directory contains PHTML files which are the actual HTML templates used to render the content of the admin pages. These templates determine the layout and design of the admin interface.

By understanding this structure, developers can efficiently navigate and modify the necessary files to create a custom admin theme in Magento 2. This knowledge is crucial for making specific and effective customizations.

You May Also Read: How to Speed up Your Magento 2 Store: 15 Tips to Follow

3. Creating the Basic Theme Structure

3.1 Setting Up the Theme Directory

  • Creating the Directory Structure for the Custom Admin Theme: To start, you need to create the directories for your custom admin theme within Magento 2’s theme folder. The typical path looks like this:
    app/design/adminhtml/VendorName/ThemeName/
    

Here, replace ‘VendorName’ with your company or developer name and ‘ThemeName’ with the name of your theme.

  • Naming Conventions and Best Practices:
    • Use meaningful names for your directories and files to make your theme easier to understand and manage.
    • Stick to lowercase letters and avoid spaces; use underscores (_) or hyphens (-) instead.
    • Example:
      app/design/adminhtml/mycompany/customtheme/
      

3.2 Defining the Theme in ‘theme.xml’

  • Detailed Explanation of the ‘theme.xml’ File: The theme.xml file is the main configuration file for your theme. It tells Magento important details about your theme.
  • Setting Up Theme Metadata (Name, Parent Theme, etc.):
    • Create a ‘theme.xml’ file inside your theme directory:
      app/design/adminhtml/mycompany/customtheme/theme.xml 
      
    • Add the following content to the ‘theme.xml’ file:
      <theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
      <title>Custom Admin Theme</title> 
      <parent>Magento/backend</parent> 
      <media>
      <preview_image>media/preview.jpg</preview_image> 
      </media>
      </theme>
      

Note:

  • ‘title’: The name of your theme.
  • ‘parent’: The parent theme from which your theme will inherit settings and files. Typically, it’s Magento/backend for admin themes.
  • ‘preview_image’: Optional. A path to an image that shows a preview of your theme.

3.3 Registering the Theme with ‘registration.php’

  • Purpose of ‘registration.php’: The ‘registration.php’ file is used to register your theme with Magento. This lets Magento know that your theme exists and can be used.
  • How to Properly Register the Custom Theme in Magento 2:
    • Create a registration.php file inside your theme directory:
      app/design/adminhtml/mycompany/customtheme/registration.php
      Add the following content to the registration.php file:
      php
      Copy code
      <!--?php
      \Magento\Framework\Component\ComponentRegistrar::register(
      \Magento\Framework\Component\ComponentRegistrar::THEME,
      'adminhtml/mycompany/customtheme',
      __DIR__
      );
      
  • This code tells Magento to register a theme located in the ‘adminhtml/mycompany/customtheme’ directory.

By following these steps, you’ll have the basic structure for your custom admin theme set up. This structure is essential for organizing your files and ensuring Magento can recognize and apply your theme properly.

4. Customizing the Admin Layout and Templates

4.1 Apply a custom theme in Admin

  • Prerequisites:
    • Set your application to the developer mode. The application mode influences the way static files are cached.
    • Create a custom theme for the Admin panel.
    • Add a new custom module or decide to use an 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):
      
              <module name="Mycompany_Customtheme" setup_version="2.0.1"> <!-- Example: "Magento_Backend" -->
              <sequence>
              <module name="Magento_Theme"/>
              <module name="Magento_Enterprise"/> <!-- For Enterprise versions only -->
              </sequence>
              </module>        
          
  • 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 the browser and view the new theme applied.
  • Specify the custom Admin theme in ‘di.xml’:
    • You need to specify the admin theme to be used in the ‘<your_module_dir>/etc/di.xml’ file. Add it, if the file does not yet exist in your module.
    • In ‘ <your_module_dir>/etc/di.xml’ add the following (replace the placeholders with the vendor name and theme code of your Admin theme):
      
              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      
                  <!-- Admin theme. Start -->
                  <type name="Magento\Theme\Model\View\Design">
                  <arguments>
                  <argument name="themes" xsi:type="array">
                  <item name="adminhtml" xsi:type="string">adminhtml/mycompany/customtheme</item> <!-- Example: "Magento/backend" -->
                  </argument>
                  </arguments>
                  </type>
                  <!-- Admin theme. End -->
                  </config>                          
          

4.2 Modifying Layout XML Files

  • Introduction to Layout XML Files and Their Role in Magento 2:
    • Layout XML files in Magento 2 define the structure and layout of pages. They determine how different blocks of content are arranged and displayed.
    • For the admin panel, these files control the layout of the backend interface, making it possible to customize the appearance and functionality.
  • How to Override and Customize Layout XML Files for the Admin Panel:
    • To customize the admin layout, you can override existing XML files or create new ones in your custom theme.
    • First, identify the layout XML file you want to customize. Admin layout files are usually found in:
      vendor/magento/module-name/view/adminhtml/layout/
      
  • To override a layout file, create a corresponding file in your theme’s layout directory:
    app/design/adminhtml/mycompany/customtheme/Magento_ModuleName/layout/
    
  • For example, to customize the admin dashboard layout, copy ‘adminhtml_dashboard_index.xml’ to your theme’s layout directory and modify it as needed:
    
    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
    <!-- Add custom blocks or modify existing ones here -->
    <referenceContainer name="content">
    <block class="Vendor\Module\Block\CustomBlock" name="custom.block"/>
    </referenceContainer>
    </body>
    </page>
    
  • This way, you can add, remove, or rearrange blocks on the admin dashboard.

4.3 Customizing Admin Templates

  • Understanding Magento 2 Template Files:
    • Template files in Magento 2 are PHP files with the ‘.phtml’ extension. They contain the HTML and PHP code used to render content on the page.
    • In the admin panel, these files are used to generate the interface elements and layouts.
    • How to Create and Modify PHTML Files for Custom Admin Templates:
  • To customize admin templates, locate the original .phtml files. These are usually found in:
    vendor/magento/module-name/view/adminhtml/templates/
    
  • To override a template, create a corresponding file in your theme’s templates directory:
    app/design/adminhtml/mycompany/customtheme/Magento_ModuleName/templates/
    
  • For example, to customize the admin login page template, copy ‘login.phtml’ to your theme’s templates directory and modify it as needed:
    
    <!-- File: app/design/adminhtml/mycompany/customtheme/Magento_Backend/templates/auth/login.phtml -->
    <div class="custom-login-container">
    <!-- Custom HTML and PHP code -->
    <?php echo $this->escapeHtml($block->getWelcomeText()); ?>
    </div>
    

This allows you to change the HTML structure, add new elements, or modify existing ones to better suit your requirements.

By understanding and using layout XML files and PHTML templates, developers can effectively customize the Magento 2 admin panel. This enables you to create a more tailored and efficient backend interface, improving the overall user experience for administrators.

5. Styling the Admin Theme

5.1 Adding Custom CSS

  • How to Create and Include Custom CSS Files in the Admin Theme:
    • To add custom CSS to your admin theme, you need to create CSS files and include them in your theme.
    • First, create a directory for your CSS files:
      app/design/adminhtml/mycompany/customtheme/web/css/
      
    • Inside this directory, create your custom CSS file, for example, ‘custom.css’:
      /* File: app/design/adminhtml/mycompany/customtheme/web/css/custom.css */
      body {
      background-color: #f0f0f0;
      }
      .custom-header {
      font-size: 16px;
      color: #333;
      }
      
    • Next, include this CSS file in your theme’s requirejs-config.js:
      var config = {
      paths: {
      'css/custom': 'css/custom'
      }
      };
      
    • Place this file in:
      app/design/adminhtml/mycompany/customtheme/requirejs-config.js
      
    • This will ensure that your custom CSS is loaded in the admin panel.
  • Best Practices for Organizing and Managing CSS:
    • Modular Approach: Break your CSS into smaller, reusable modules. For example, create separate files for layout, typography, and components.
    • Naming Conventions: Use consistent naming conventions for classes and IDs to make your CSS easier to read and maintain.
    • Comments: Add comments to your CSS to explain the purpose of specific styles, especially if they are complex or non-standard.
    • File Structure: Organize your CSS files logically within the ‘web/css’ directory. For example:
      web/css/
      ├── base.css
      ├── layout.css
      ├── components/
      │   ├── buttons.css
      │   ├── forms.css
      

5.2 Using LESS and SASS for Advanced Styling

  • Introduction to Using LESS and SASS in Magento 2 Themes:
    • LESS and SASS are CSS pre-processors that allow you to write more maintainable and scalable stylesheets. They add features like variables, nested rules, and mixins to regular CSS.
    • Magento 2 supports both LESS and SASS out of the box.
  • Configuring and Compiling LESS/SASS Files:
    • To use LESS, create a less directory within your theme’s ‘web’ directory:
      app/design/adminhtml/mycompany/customtheme/web/css/source/_custom.less
      
    • Add your custom styles in ‘_custom.less’:
      @body-bg: #f0f0f0;
      body {
      background-color: @body-bg;
      }
      .custom-header {
      font-size: 16px;
      color: #333;
      }
      
    • In your theme’s ‘theme.xml’, include the LESS file:
      <theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
      <media>
      <css>
      <file src="css/source/_custom.less"/>
      </css>
      </media>
      </theme>         
      
    • Magento will automatically compile the LESS files when you deploy the theme.

5.3 Customizing Admin UI Components

  • Overview of Magento 2 UI Components:
    • Magento 2 UI components are building blocks used to create the admin interface. They include elements like buttons, forms, grids, and modal windows.
    • These components are defined using XML, JavaScript, and PHTML files and can be customized to fit your design requirements.
  • How to Customize and Style Admin UI Components:
    • To customize UI components, locate the component you want to modify in the module’s ‘view/adminhtml/ui_component’ directory.
    • For example, to customize the admin grid, copy the relevant XML file to your theme:
      app/design/adminhtml/mycompany/customtheme/Magento_ModuleName/ui_component/       
      
    • Modify the XML file to change the component’s behavior or appearance.
    • To style the components, add CSS or LESS rules specific to those components in your custom stylesheet:
      /* Custom styles for admin buttons */
      .admin__button {
      background-color: #0056b3;
      color: #fff;
      }
      

By following these steps, you can effectively style your custom admin theme, making it visually appealing and user-friendly. Understanding how to add and manage custom CSS, use LESS/SASS, and customize UI components will enable you to create a unique and efficient admin interface in Magento 2.

6. Adding Custom JavaScript

6.1 Including Custom JavaScript Files

  • How to Include Custom JavaScript Files in the Admin Theme:
    • To add custom JavaScript to your admin theme, you need to create JavaScript files and include them in your theme.
    • First, create a directory for your JavaScript files:
      app/design/adminhtml/mycompany/customtheme/web/js/
      
    • Inside this directory, create your custom JavaScript file, for example, ‘custom.js’:
      
      // File: app/design/adminhtml/mycompany/customtheme/web/js/custom.js
      define(['jquery'], function($) {
      'use strict';
      $(document).ready(function() {
      console.log('Custom admin theme JavaScript loaded');
      });
      });
      
    • Next, include this JavaScript file in your theme’s ‘requirejs-config.js’:
      var config = {
      map: {
      '*': {
      'customJs': 'js/custom'
      }
      }
      };
    • Place this file in:
      app/design/adminhtml/mycompany/customtheme/requirejs-config.js
    • This configuration ensures that your custom JavaScript is loaded in the admin panel.
  • Best Practices for Structuring and Organizing JavaScript Code:
    • Modular Approach: Organize your code into small, reusable modules. This makes your code easier to maintain and debug.
    • Naming Conventions: Use clear and consistent names for your files and functions to improve readability.
    • Comments: Add comments to explain the purpose of your code, especially for complex logic.
    • File Structure: Organize your JavaScript files logically within the ‘web/js’ directory. For example:
      web/js/
      ├── components/
      │   ├── custom-component.js
      ├── custom.js
      ├── requirejs-config.js
      
      

6.2 Using RequireJS for Modular JavaScript

  • Introduction to RequireJS in Magento 2:
    • RequireJS is a JavaScript module loader used in Magento 2. It allows you to define JavaScript modules and manage dependencies between them.
    • Using RequireJS, you can load only the JavaScript files needed for a particular page, improving performance.
  • How to Define and Use RequireJS Modules in the Admin Theme:
    • To define a RequireJS module, use the define function. Here’s an example:
      // File: app/design/adminhtml/mycompany/customtheme/web/js/custom-module.js
      define(['jquery'], function($) {
      'use strict';
      return function(config, element) {
      $(element).text('Hello, Magento 2!');
      };
      });
      
    • To use this module in the admin panel, include it in your layout XML or a PHTML file:
      <!-- File: app/design/adminhtml/mycompany/customtheme/Magento_Backend/layout/default.xml -->
      <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
      <head>
      <script type="text/x-magento-init">
      {
      "*": {
      "customJs": {}
      }
      }
      </script>
      </head>
      </page>
      
    • This code tells Magento to load your custom JavaScript module when the admin page is rendered.

By understanding how to include custom JavaScript files and use RequireJS, developers can add dynamic functionality to their Magento 2 admin themes. This enables the creation of interactive and responsive interfaces, enhancing the overall user experience.

7. Advanced Customizations

7.1 Customizing Admin Grids and Forms

  • How to Customize Admin Grids and Forms:
    • Admin grids and forms are used to display and manage data in the Magento 2 admin panel. Customizing these can help make data management more efficient and tailored to specific needs.
    • To customize an admin grid, you typically work with XML configuration files. These files define the structure and behavior of the grid.
  • Adding Custom Columns and Fields:
    • Adding Columns to Admin Grids:
      • Locate the XML file that defines the grid you want to customize, usually found in the module’s ‘view/adminhtml/ui_component’ directory.
      • Copy this file to your theme’s directory:
        app/design/adminhtml/mycompany/customtheme/Magento_ModuleName/ui_component/grid_name.xml
        
      • Add a custom column to the XML file
        <column name="custom_column" class="Vendor\Module\Ui\Component\Listing\Columns\CustomColumn">
        <settings>
        <label translate="true">Custom Column</label>
        </settings>
        </column>                     
        
      • Create the corresponding PHP class to define the behavior of the custom column:
        namespace Vendor\Module\Ui\Component\Listing\Columns;
        
        use Magento\Ui\Component\Listing\Columns\Column;
        
        class CustomColumn extends Column
        {
        public function prepareDataSource(array $dataSource)
        {
        if (isset($dataSource['data']['items'])) {
        foreach ($dataSource['data']['items'] as & $item) {
        $item[$this->getData('name')] = 'Custom Value';
        }
        }
        return $dataSource;
        }
        }                                              
        
    • Adding Fields to Admin Forms:
      • Locate the form XML file in the module’s ‘view/adminhtml/ui_component’ directory.
      • Copy this file to your theme’s directory:
        app/design/adminhtml/mycompany/customtheme/Magento_ModuleName/ui_component/form_name.xml
        
      • Add a custom field to the XML file:
        <fieldset name="custom_fieldset">
        <field name="custom_field">
        <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
        <item name="label" xsi:type="string" translate="true">Custom Field</item>
        <item name="dataType" xsi:type="string">text</item>
        <item name="formElement" xsi:type="string">input</item>
        </item>
        </argument>
        </field>
        </fieldset>                       
        

7.2 Creating Custom Admin Widgets

  • Overview of Magento 2 Admin Widgets:
    • Admin widgets in Magento 2 are reusable UI components that provide specific functionality, such as buttons, grids, or forms. They make it easier to add consistent features across the admin panel.
  • How to Create and Integrate Custom Widgets in the Admin Theme:
    • Creating a Custom Widget:
      • Create the widget JavaScript file in your theme’s directory:
        app/design/adminhtml/mycompany/customtheme/web/js/custom-widget.js
        
      • Define the custom widget using jQuery UI widget factory:
        define(['jquery', 'jquery/ui'], function($) {
        $.widget('vendor.customWidget', {
        _create: function() {
        this.element.text('Custom Widget Loaded');
        }
        });
        return $.vendor.customWidget;
        });                            
        
    • Integrating the Custom Widget:
      • Include the widget in your layout XML or PHTML file:
        <!-- File: app/design/adminhtml/mycompany/customtheme/Magento_ModuleName/layout/default.xml -->
        <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <head>
        <script src="js/custom-widget.js"/>
        <script type="text/x-magento-init">
        {
        "*": {
        "vendor/customWidget": {}
        }
        }
        </script>
        </head>
        </page>
        
    • This code tells Magento to load and initialize your custom widget on the specified admin page.

By understanding how to customize admin grids, forms, and create custom widgets, developers can add powerful, tailored features to the Magento 2 admin panel. These advanced customizations help improve the usability and functionality of the backend, making it more efficient for administrators to manage the store.

8. Testing and Debugging

8.1 Testing the Custom Admin Theme

  • How to Test the Custom Admin Theme for Functionality and Appearance:
    • Manual Testing:
      • Functionality: Log in to the Magento admin panel and navigate through various sections to ensure all customizations are working correctly. Check custom grids, forms, and widgets to make sure they behave as expected.
      • Appearance: Look at the visual elements of your theme, such as layout, colors, fonts, and spacing. Make sure everything looks good and is consistent across different browsers and screen sizes.
    • Automated Testing:
      • Use tools like Selenium to automate the testing of repetitive tasks. This ensures that your theme functions correctly even after multiple updates.
      • Write test scripts to cover various scenarios, such as form submissions, data validation, and navigation.
  • Tools and Techniques for Thorough Testing:
    • Browser Developer Tools: Use Chrome DevTools or Firefox Developer Tools to inspect elements, debug JavaScript, and analyze performance.
    • Responsive Design Testing: Check your theme on different devices and screen sizes using tools like BrowserStack or responsive design mode in browser developer tools.
    • Magento Test Framework (MTF): Use Magento’s built-in testing framework to write and run functional tests for your custom theme.

8.2 Debugging Common Issues

  • Common Issues Faced During Custom Theme Development:
    • CSS/JS Not Loading: Often due to incorrect file paths or missing files.
    • Layout Problems: Misconfigured XML files or incorrect block names.
    • JavaScript Errors: Syntax errors, missing dependencies, or issues with RequireJS configuration.
    • Slow Performance: Unoptimized CSS/JS, excessive DOM manipulation, or inefficient SQL queries.
  • Debugging Techniques and Tools:
    • Enable Magento Developer Mode: This mode provides detailed error messages and improves logging. You can enable it with:
      bin/magento deploy:mode:set developer                      
      
    • Log Files: Check Magento’s log files in var/log/ for detailed error messages and stack traces.
    • Browser Console: Use the console in Chrome DevTools or Firefox Developer Tools to identify and fix JavaScript errors.
    • Xdebug: A PHP debugging tool that allows you to set breakpoints, step through code, and inspect variables. Integrate it with your IDE (like PHPStorm) for a smoother debugging experience.
    • Network Analysis: Use the Network tab in browser developer tools to monitor HTTP requests and identify any slow or failed requests.
    • Magento Profiler: Enable the built-in profiler to analyze performance and identify bottlenecks in your theme.

By thoroughly testing and debugging your custom admin theme, you ensure it functions correctly and looks good. Using the right tools and techniques helps you quickly identify and fix issues, resulting in a smooth and reliable admin experience for Magento users.

You May Also Read: 10 Marketing Automation Tools to Optimize Your Magento Store

9. Deployment and Maintenance

9.1 Packaging the Custom Theme

  • How to Package the Custom Admin Theme for Deployment:
    • Prepare the Files: Ensure all your theme files (CSS, JavaScript, images, XML, PHTML) are correctly organized in your theme directory
      app/design/adminhtml/mycompany/customtheme/   
      
    • Create a Composer Package: To make it easier to manage and deploy your theme, create a composer.json file in your theme directory:
      {
      "name": "mycompany/customtheme",
      "description": "Custom Admin Theme for Magento 2",
      "type": "magento2-theme",
      "version": "1.0.0",
      "require": {
      "php": "~7.4.0||~8.1.0"
      },
      "autoload": {
      "files": [
      "registration.php"
      ]
      }
      } 
      
    • Archive the Theme: Compress the entire theme directory into a ZIP file or use a version control system like Git to manage and distribute the theme.
  • Best Practices for Version Control and Theme Updates:
    • Use Version Control: Track changes using Git. This helps you manage versions, collaborate with others, and revert to previous states if needed.
    • Tag Releases: Use tags in Git to mark stable releases of your theme. This makes it easier to manage and deploy specific versions.
    • Document Changes: Keep a changelog to document what changes are made in each version. This helps in tracking updates and understanding the theme’s evolution.
    • Automate Deployments: Use CI/CD tools like Jenkins or GitHub Actions to automate the deployment process, ensuring consistent and error-free deployments.

9.2 Deploying the Theme in a Production Environment

  • Steps for Deploying the Custom Admin Theme in a Live Environment:
    • Backup Your Site: Before making any changes, ensure you have a full backup of your site, including files and the database.
    • Upload the Theme: Transfer the theme files to the production server. If using a Composer package, add it to the composer.json file of your Magento project and run composer update.
    • Enable the Theme: Log in to the Magento admin panel and navigate to Content > Design > Configuration. Select the configuration scope and apply your custom admin theme.
    • Deploy Static Content: Run the following command to deploy static content:
      bin/magento setup:static-content:deploy                   
      
    • Clear Cache: Clear the Magento cache to ensure all changes take effect:
      bin/magento cache:clean          
      
  • Post-Deployment Checks and Optimizations:
    • Verify Functionality: Log in to the admin panel and check all sections to ensure everything works as expected. Pay attention to custom grids, forms, and widgets.
    • Check Appearance: Confirm that the theme looks correct across different browsers and screen sizes. Fix any visual issues you encounter.
    • Performance Testing: Use tools like Google Lighthouse or Magento’s built-in profiler to check the performance of the admin panel. Optimize any slow-loading elements.
    • Monitor Logs: Keep an eye on the log files (var/log/) for any errors or warnings that might indicate issues with the theme.
    • User Feedback: If possible, get feedback from users who regularly use the admin panel to identify any usability issues or areas for improvement.

By carefully packaging, deploying, and maintaining your custom admin theme, you ensure a smooth and efficient transition to the new theme in the production environment. Following best practices and performing thorough checks helps maintain a stable and reliable Magento admin panel.

You May Also Read: Supercharge Your Magento 2 Store Using Elasticsearch

Conclusion

Creating a custom admin theme in Magento 2 enhances the user experience and aligns the admin panel with your business needs. By following the steps outlined in this guide—setting up the theme structure, customizing layouts and templates, adding custom styles and JavaScript, and performing thorough testing—you can develop a robust and efficient admin theme. Remember to package and deploy your theme carefully and keep it well-maintained. With these skills, you can create a seamless and visually appealing backend that boosts productivity and usability for administrators, contributing to your overall E-commerce success. Happy developing!

Sanjay Singhania, Project Manager

Sanjay, a dynamic project manager at Capital Numbers, brings over 10 years of experience in strategic planning, agile methodologies, and leading teams. He stays updated on the latest advancements in the digital realm, ensuring projects meet modern tech standards, driving innovation and excellence.

Share

Recent Awards & Certifications

  • World HRD Congress
  • G2
  • Dun and Bradstreet
  • ISO 9001 & 27001
  • SOC2
[class^="wpforms-"]
[class^="wpforms-"]
[class^="wpforms-"]
[class^="wpforms-"]