[Fixed] Magento 2 Unable to load theme by specified key error

magento_2_unable_to_load_theme_by_specified_key_featured

You have been seeing this error lately. It says “unable to load theme by specified key“.

magento_2_unable_to_load_theme_by_specified_key

Ouch. So what is the cause of this, and how to fix this?

This article answers both questions above.

The cause of Unable to load theme by specified key error

The root of this error is: you are having one or more theme deleted in your code, but not fully deleted in related table(s) in your site’s Database.

There are two common scenarios when you encounter this error.

The first one is when you migrate Magento version 1 to Magento version 2, and the theme you were using did not support Magento version 2.

The second one is when you delete your theme not thoroughly.

Either way, you would be advised to fix the error by one simple way.

The solution for Unable to load theme by specified key error

In order to fix this error, you have to remove the row of the theme with the key in the error log in the core_config_data table.

You can either do this via SSH or SQL Admin tools.

Using SSH

For those of you who are more experienced and want to get things done fast, use SSH.

  • Open a Terminal Emulator such as PuTTY. Log in to your SQL account.
  • Then input:
    delete from core_config_data where path = 'design/theme/theme_id' and value = '<your key>';
  • Note: <your key> here is the key in the error log. With the example above, <your key> is 4.
    magento_2_unable_to_load_theme_by_specified_key_number
  • Then flush cache.

Using a SQL Admin tools

For those of you who prefer a more visual way to fix things, use a SQL Admin tool.

  • Open a SQL Admin tool such as Adminer. Log in to your Adminer account.
  • Find table named core_config_data.
  • Find the row with the path = ‘design/theme/theme_id’ and value = ‘<your key>’.
    magento_2_unable_to_load_theme_by_specified_key_adminer
  • Then flush cache.

Unable to load theme by specified key error: In conclusion,

This problem is quite common and yet easy to fix. Following this guide should make your website back to normal, without the asynchronicity of the theme files and Database.

If you do migration from Magento version 1 to version 2, hire Magento experts to migrate for you to prevent further hard-to-notice bugs and errors like this.

Do you find this debug guide easy to follow? Do you have any more question? Let us know in the comment below.

Take a look at our gallery of premium and free Magento 2 themes. Click the image below!

magento_2_themes

[Solved] Magento 2 theme CSS not loading

Magento-2-theme-CSS-not-loading

In our previous article, we have written about what to do when you accidentally delete your Magento default theme. But it is just one simple issue that can happen to your theme when you configure your website code.

Another more complex problem when configuring the website code is Magento 2 theme CSS not loading problem. You are changing the website code, and when you reload, all of the CSS of your website leaves you with no good-bye. And no matter how much time you change your theme, you beautiful multi-store website now has gone back to 2000s like this

Magento 2 theme CSS not loading example

This issue is caused by two main reasons: missing the .htaccess file in “pub/static/” folder or deploy incorrectly. To fix this, you have to either have your .htaccess restored or deploy all store views and themes.

Have your .htaccess restored

The most common cause of CSS not loading problem for Magento 2 is accidentally delete .htaccess in “pub/static/”. You can be sure that you have this problem by going to that folder and see this

magento 2 theme css not loading due to missing htcaccess in folder

when it actually has to be like this

magento 2 theme css loaded

To fix this, if you have a backup of your site, restore the latest backup that the .htaccess in pub/static/ not missing.

If you don’t have a backup of your site, you can either download our .htaccess and upload to the folder, or just restore it manually.

Deploy all stores and all themes

Deploy all stores

Another common mistake multi-store site owners make when setting up their sites ís deploy the wrong store view. If you have more than one store view for users with different languages, when you deploy, you can use the command like this:

php bin/magento setup:static-content:deploy 

(add “ -f” at the end if Magento version 2.2.x or higher)

This usually leads to only your en_US store deployed.

Magento 2 theme css not loading due to deploy only in en_US

So you have all other languages store view of your site not deployed. Now you have to deploy with all other store views that correlates with other language installed on your website. These can be done in 2 steps:

  1. Get your code language
    Go to Magento Admin > Store > Settings > Configuration > Select Store view
    There you have a list of languages enabled on your website. You have to get the language code of each language enabled, so click each one at a time.
    Magento 2 theme css not loading get language codeLet’s say we are getting the code of France language. Now hover over the language on the right of Locale options > Locale and right click, Inspect. Find the line with
    Selected=”select” in <td class=”value”> </td>. The language code is in that line’s <option value=”language_code”
    Magento 2 theme css not loading get language code 2
  2. Deploy your site in that language using the language code
    With the language code you’ve just got, input this line of code:

    php bin/magento setup:static-content:deploy language_code

    (add “ -f” at the end if Magento version 2.2.x or higher)
    In our example, we input:

    php bin/magento setup:static-content:deploy fr_FR

    (add “ -f” at the end if Magento version 2.2.x or higher)
    After that, you should be able to see something like this
    Magento 2 theme css loaded in french
    Then repeat from step 1 with each of the language view for your website.

Deploy with all themes

Usually, when you use a premium theme, after changing CSS and JS files, you only need to deploy using the code:

php bin/magento setup:static-content:deploy -f

However, in some rare cases, the theme is not fully developed, that it cannot be deployed using the above command. If you have tried all of the methods above, try to deploy the exact theme currently enabled on your site using the command:

php bin/magento setup:static-content:deploy --theme Vendor/Theme_name -f

For example,

php bin/magento setup:static-content:deploy --theme BSS/Thinnk -f

Magento 2 theme CSS not loading bug: in conclusion,

There you have your Magento 2 theme CSS not loading issue debugged. You can do this by either restoring .htaccess file in /pub/static or deploy correctly. Have a beautiful website working with multiple languages again!

Magento 2 theme css loaded beautifully

So, do you have any more question regarding your Magento 2 theme bug? Let us know in the comment section below.

Also, if you want to upgrade your theme to a bug-free, rich-featured theme with a 5-star support team, you might want to take a look at the theme we spend months developing

Magento 2 theme css not loadning