It’s frustrating when you see “This File Should Not Be Imported in This Context” while importing a JSON file.
This is a contextual error, which means you are trying to import a file to the wrong location. Besides that, corrupted/incomplete files, limited file upload size, and incorrect file permission can also cause file importing issues.
In this article, we will explore all the causes of the contextual error and provide solutions for each. We will also guide you on how to avoid this issue in the future.
JSON file is a format used to export and import layouts and templates within the Divi ecosystem for future use. |
Resolving “This File Should Not Be Imported in This Context” Error: Causes and Solutions
We have already mentioned there are a few reasons why you may be facing an error while importing a file. Now let’s dive into the solutions for each:
1. Contextual Error (Most Common Reason)
Contextual error occurs when you attempt to import a file into the wrong location within the Divi system. For example, if you export a file from a Divi Library, you have to import it into the Divi Library.
The same rule goes for Theme Builder as well as Divi Builder (page and posts.)
But how can you determine the source of the template or layout you exported?
In that case, simply open the JSON file in a text editor and look for its specific context or identifier in the first line. Each type of layout or template you export will have a specific identifier. For example:
- “context”:”et_builder” – indicates the file is exported from Divi builder (individual page/post).
- “context”:”et_builder_layouts” – means the file is exported from Divi Library.
- “context”:”et_theme_builder”- indicates the file is exported from Divi Theme Builder.
To show you how to do that, we have exported a page we designed with DiviFlash’s modules. We have also exported a template from Divi Theme Builder and a layout from Divi Library.
Now we will open all the exported JSON files using a text editor. Here’s what they look like:
Once you know the identifier, you can import your file to the right place to avoid “This File Should Not Be Imported in This Context” error.
2. Corrupted or Empty JSON File
When you export a JSON file from an unverified source, then it’s highly likely you may encounter import errors for corrupted or empty JSON files.
- Corrupted file means that the file’s content is damaged in a way that cannot be easily recovered. This happens due to file transfer errors. It can also happen due to manual editing, which can cause syntax errors.
- Empty file indicates that the JSON file does not contain any data. This can happen due to an incomplete export or the layout or template was not saved correctly.
Although these issues are not common, they can lead to file import errors. Therefore, it’s best to re-download the file and try importing it again.
Also, if you frequently transfer layouts or templates between your sites, consider using Divi Cloud. This one will ensure that your files are transferred securely and without any corruption or data loss.
Additionally, always try to get layouts or templates from reputable sources to ensure the files are valid and free from corruption.
3. Limited Upload Max File Size
It may sound unusual, but “maximum upload file size” on your site’s server can actually cause an import issue.
For example, if your server’s upload limit is set to 2 MB and you attempt to upload a file larger than this limit, you will encounter an error. In such cases, you will need to increase the upload limit.
To ensure that the error is related to the file size limit, go to your WordPress dashboard > Media > Add New. There, you will see the maximum upload file size displayed under the media adding box.
Also check your JSON file size, checking its properties.
If your file size is larger than your site’s maximum upload file size, you will need to increase the limit on your server. You can do that in many different ways:
- Contact your hosting provider to adjust the upload limit.
- Use a plugin like “Wp Maximum Upload File Size” to change the limit.
- Modify the functions.php file. If you are not comfortable with coding, it’s best to skip this option. Otherwise, any wrong step could break your site.
To Modify the functions.php file, go to your WordPress dashboard > Appearance > Theme File Editor. Then, add the following code to the end of the functions.php file and click “Update File”:
@ini_set( ‘upload_max_filesize’, ’64M’ );
By adding this code to your theme’s functions.php file, you can increase the maximum file upload size for your WordPress site to 64MB.
Note: Remember, when you change your theme, the settings you made will revert to the default.
4. Wrong File Permissions
Another uncommon reason to face file upload errors is incorrect file permissions. This type of issue happens when your server settings limit your ability to read, write, or execute files, stopping your uploads from going through.
In this situation, try to check your site’s file permissions to identify any issues. You can do that by accessing your WordPress directory:
- Log in to your hosting account and open the “File Manager.”
- Go to the public_html folder or the directory where WordPress is installed.
- Right-click on wp-content, uploads, and relevant folders. Set permissions to 755.
- Next, right-click on files inside these folders and set permissions to 644.
After saving these changes, try uploading your JSON file in Divi again. If the issue persists, it’s recommended that you seek help from your hosting provider.
Note: If you don’t know how to code, avoid attempting any coding-related tasks.
Best Practices to Avoid “This File Should not be Imported in this Context” Error in the Future
Want to avoid encountering JSON file import errors on your Divi website? These best practices will help ensure smoother imports,
- Check File Context: If you are not sure from where you have exported a JSON file, open it with a text editor to check its context. This will allow you to identify the file’s context and then import it into the correct location.
- Keep JSON Files Organized: Organize your exported files properly to avoid confusion. For instance, save files from pages or posts in separate folders. Apply the same organization for files exported from Divi Theme Builder and Divi Library.
- Avoid Manual Edits: Editing a JSON file is not recommended unless you are confident in your understanding. If you rename JSON files, ensure there are no spaces in the name and that the file ends with .json.
Closing Thoughts
By now, you should have a solid understanding of how to fix “This File Should Not Be Imported in This Context” error.
We have covered all the possible reasons why you might encounter this issue and provide solutions for each one.
However, always try the first troubleshooting method before moving on to others. Also, avoid using custom code if you are not familiar with it.
In case you find anything difficult to understand in this guide, feel free to comment. We will be more than happy to assist you further.
0 Comments