We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.

Your Digital Commerce Experts
Nexcess Logo

How To Uninstall a Magento Theme: The Ultimate Guide

March 29, 2022
How to uninstall a Magento theme.

You can uninstall a Magento 2 theme in two ways:

  • By removing it from the Magento codebase and database manually.
  • By using the Magento theme uninstall command.

The method you can use depends on multiple factors, such as:

  • How the Magento 2 application was installed — using Composer or cloning GitHub.
  • How the theme was installed — using Composer or by uploading theme files.

If you installed the theme by uploading the files, you need to uninstall it manually regardless of how you installed Magento. But, if you installed it using Composer, then the removal method varies based on the Magento installation process.

Keep reading to learn:

Prerequisites for Uninstalling a Magento 2 Theme

Follow these steps before you remove a theme in Magento 2.

1. Ensure the Theme Isn’t Applied to a Store View

Check the theme isn’t applied to a store view.

Go to Content > Design > Configuration in the Magento admin. Ensure the theme you wish to uninstall isn’t assigned to a store view. If it is, follow Adobe’s guide demonstrating how to change a theme in Magento 2 and assign an alternate theme.

2. Verify the Theme Isn’t Set as a Parent Theme

Verify the theme isn’t set as a Parent theme to another theme.

Go to Content > Design > Themes in the Magento admin panel. Check the Parent Theme column to verify your custom theme isn’t listed there. If it is, uninstall the child theme first and then the parent theme.

3. Back up the Magento Database and Filesystem

Adobe deprecated Magento’s inbuilt backup functionality in Magento 2.3.0 and later versions. Although you can still use it from the command-line interface (CLI), they no longer recommend using it.

Consult your hosting provider for options to back up your Magento store and explore an alternative binary backup tool such as Percona XtraBackup to backup the database.

If you’re a Nexcess customer, you can take an on-demand backup of your Magento store in addition to the free 30-day incremental backups. Log in to your Client Portal and go to Plan Dashboard > Backups > Create Backup to back up your store.

4. Change the Magento Operation Mode to Developer or Default

Clear generated classes and proxies from the Magento CLI using the following command:

<pre><code>

$ rm -rf <magento-root>/generated/metadata/* <magento-root>/generated/code/*

</pre></code>

Then, switch Magento to the developer mode using:

<pre><code>

$ php bin/magento deploy:mode:set developer

</pre></code>

Steps To Uninstall a Magento 2 Theme Manually

If you’re using a custom Magento theme, you may have installed it manually by placing the theme files in a directory in the app/design folder in the Magento root.

Here’s how you can manually remove a theme in Magento 2:

Step 1: Enable Maintenance Mode

Put your store in maintenance mode to disable bootstrapping when you uninstall the Magento 2 theme.

Log in to your Magento 2 server as the Magento file system owner and run the following command to enable maintenance mode:

<pre><code>

$ php bin/magento maintenance:enable

</pre></code>

Step 2: Remove the Theme Directory From the Magento Filesystem

Manually installed Magento themes are usually placed in the app/design directory in the Magento root. Find the path to where the theme files are placed in the Magento root and delete the theme folder.

For example:

<pre><code>

$ rm -rf <magento-root>/app/design/frontend/<vendor-name>

</pre></code>

Step 3: Remove the Theme Record From the Magento Database

Next, to remove the Magento 2 theme, delete all records and references to the theme inside the store database using the following command:

<pre><code>

$ mysql -u <user> -p -e "delete from <dbname>.theme where theme_path ='<vendor>/<theme>' AND area ='frontend' limit 1"

</pre></code>

Replace the following placeholders before executing the command:

  • <user>: Enter the Magento database username.
  • <dbname>: Enter the Magento database name.
  • <vendor>/<theme>: Enter the relative path to the theme directory.

Step 4: Clear Caches and Disable Maintenance Mode

Clear Magento cache to finish uninstalling Magento 2 theme.

To complete the uninstallation process, clear all Magento caches using the following command:

<pre><code>

$ php bin/magento cache:clean

</pre></code>

Finally, disable maintenance mode using:

<pre><code>

$ php bin/magento maintenance:disable

</pre></code>

If you notice any errors on the frontend, clear the cache of other caching applications such as Varnish or Redis.

Steps To Uninstall a Magento 2 Theme Using Composer

The steps to uninstall a Magento 2 theme using Composer vary slightly based on the Magento 2 installation method. If you installed Magento using Composer, you can uninstall the theme using a CLI command.

However, if you installed Magento by cloning its Git repo, you’ll need to remove the theme from Magento’s composer.json file before using the command.

Here’s how to uninstall a Magento 2 theme using Composer:

Step 1: Remove the Theme From the Magento composer.json File (GitHub Install Only)

Note: This step is only required if you’ve installed Magento by cloning its Git repository.

Log in to the Magento file system and go to the Magento root directory.

Edit the Magento composer.json file using your preferred text editor and delete the line referencing the theme package.

Here’s a composer.json file with sample data for reference:

Edit the Magento composer.json file.

After removing the reference to the theme package from the “require” section, update the Magento project dependencies via the CLI using:

<pre><code>

$ composer update

</pre></code>

Now, you can safely run the Magento theme uninstall command as described in the next step.

Note: You can also remove the dependency using the composer remove command. However, in that case, make sure you delete the theme record from the Magento database manually.

Step 2: Run the Magento Theme Uninstall Command

Execute the following command in the CLI:

<pre><code>

$ php bin/magento theme:uninstall --backup-code --clear-static-content {theme path}

</pre></code>

This command:

  • Checks if the theme exists at the defined theme path.
  • Verifies the theme is a Composer package.
  • Checks for dependencies, verifies the absence of a virtual theme, and that the theme isn’t currently in use.

If all checks are successful, it will:

  • Put the store in maintenance mode and back up the codebase if the --backup-code command is used.
  • Remove the theme from the Magento database tables first and then from the codebase with composer remove.
  • Clear cache files and generated classes. If --clear-static-content is specified, it will also clear static view files.
  • Disable maintenance mode once the process is complete.

If dependencies exist, you may see an error such as:

Magento 2 theme removal error due to theme dependencies.

Resolve the dependency issue and rerun the uninstall command. If the theme relies on another theme, you can remove both simultaneously as follows:

<pre><code>

$ php bin/magento theme:uninstall frontend/SampleCorp/SampleModuleTheme frontend/SampleCorp/SampleModuleThemeDepend --backup-code

</pre></code>

Final Thoughts: How To Uninstall a Magento Theme

No matter how you uninstall a Magento 2 theme, make sure you consult your theme developers’ documentation for extra steps such as removing any associated extensions. It also helps to take a backup of your Magento store to avoid data loss.

Get access to on-demand backups at the click of a button and simplify operating a Magento store by signing up for Managed Magento hosting with Nexcess today.

Maddy Osman
Maddy Osman

Maddy Osman is a WordPress expert and WordCamp US speaker. She is a WordCamp Denver organizer and also operates The Blogsmith, an SEO content agency for B2B tech companies that works with clients like HubSpot, Automattic, and Sprout Social. Learn more about The Blogsmith's process and get in touch to talk content strategy: www.TheBlogsmith.com