Has your WordPress Block Editor’s layout got messed up and doesn’t load properly, and Site Health Status is showing you the performance issue, “The Rest API did not behave correctly“? You’re in the right place.
In this tutorial, I will guide you on how to fix the layout of WordPress Block Editor by resolving the REST API issue.
The REST API allows you to communicate with your WordPress backend (admin section) by sending and receiving JSON objects. WordPress developers can use REST API to build powerful WordPress themes and plugins that have more dynamic access to your site’s data.
This is the complete detail of, “The Rest API did not behave correctly” issue:
The REST API is one way that WordPress and other applications communicate with the server. For example, the block editor screen relies on the REST API to display and save your posts and pages.
The REST API did not process the context query parameter correctly.
- This is how the layout of your WordPress Block Editor gets messed up and doesn’t load properly.
Following topics will be covered in this post:
- Clear your Browser Cache or Check on Another Browser
- Enable Cache All Query Strings on CDN Settings
- Disable REST API Features on Yoast Plugin
- Other Solutions
RELATED
- How to Migrate Domain and Hosting to Namecheap
- How to Set Up WP Mail in WordPress to Send Emails
- Best Cache Plugin for WordPress Block Themes
01. Clear Browser Cache or Check on Another Browser
Before you go for other solutions clear the cache of your browser and open a post in your WordPress Block Editor. If the issue is not fixed, login to your WordPress Admin section on another browser that you don’t use normally and open a post in your WordPress Block Editor.
When you update site settings, cache settings, plugin settings, or CDN settings, the new changes may not be updated on your browser, as a result your site or its features do not function properly. By clearing the cache you remove the cached data of your browser, that also includes error pages.
Go through this tutorial to learn about how to clear the cache of different browsers.
02. Enable Cache All Query Strings on CDN Settings
One of the primary causes of “The Rest API did not behave correctly“ is your CDN settings. You have not enabled Cache All Query Strings option, rather you have enabled Ignore Query Strings option that ignores the query strings of URLs.
A query string is a part of URL that assigns a values to parameters. It appear after the Question Mark (?) in the URL. For example, “https://example.com/wp-admin/post.php?post=25416&action=edit”.
When you enable Cache All Query Strings option on your CDN settings, it can reduce cache duplication and optimize cache storage.
Here, I am guiding you on how to enable Cache All Query Strings option on Namecheap Supersonic CDN settings. If your site is linked with other CDNs such as Cloudflare, StackPath, etc, you can find the relevant option there.
- Login to your Namecheap account.
- Go to Apps from the sidebar and click on the Supersonic CDN.
- Click on the Login with Namecheap button.
- Click on the Manage button.
- Click on the CDN Settings from the sidebar.
- Go to Query String Control section.
- Select Cache All Query Strings option and Update/Save the changes.
Now clear the cache of your browser, login to your WordPress Admin section, and open a post on Block Editor. The layout of Block Editor should be fixed. If doesn’t fix, try checking on another browser.
03. Disable REST API Features on Yoast Plugin
The Rest API did not behave correctly issue can also be occurred due to Yoast SEO plugin’s site feature REST API endpoint. Disabling this feature may remove the issue from your WordPress site.
- Go to Yoast SEO from the sidebar.
- Click on the Settings.
- Click on the Site features from the sidebar.
- Scroll-down to APIs section and disable the REST API endpoint feature.
- Click on the Save Changes button.
Login to your WordPress Admin section, and open a post on Block Editor to check whether the issue is fixed or not.
04. Other Solutions
If the above solutions don’t work you can try these solutions:
- Disable Your Plugins: The REST API error can also be caused by your WordPress plugins and active theme. You can disable all the plugins and enable them one-by-one to identify which one is causing the issue. If you don’t want to do this manually you can use the plugin Health Check & Troubleshooting. It disables all your plugins and uses a default theme without affecting your live site, as it does only for you.
- Check the Settings of Security Plugins: Some security-centric WordPress plugins such as Wordfence Security, WP Hide & Security Enhancer, Disable REST API, Titan Anti-spam & Security, WP Cerber Security, and NinjaFirewall have the ability to disable/block/restrict REST API. If any of the plugin is installed, you can check its settings.
- Pause your CDN: Pause your CDN temporary to check whether it is causing the issue. Your CDN can block the REST API. Its firewall can inadvertently block legitimate requests. You can check the Rule Set to confirm if the REST API is being blocked. You can remove/disable such rules and allow REST API to communicate with your site. After pausing the CDN or updating the Rule Set don’t forget to clear the cache of your browser.
- Enable Debug Mode: You can enable the WordPress Debug Mode to troubleshoot the REST API issue. The errors are stored in a debug.log file in the WP-content directory. You can search the debug.log file to find the errors which are blocking the REST API.
The Debug Mode in WordPress can be enabled by adding the below code in the wp-config.php file. After issue is resolved, remove this code from the wp-config.php file.
define( 'WP_DEBUG', true ); // Enables WP_DEBUG mode
define( 'WP_DEBUG_LOG', true );
I hope that my recommended solutions would have helped you to fix the issue, The REST API did not behave correctly. If you like this post, then don’t forget to share with other people. Share your feedback in the comments section below.
Also Read
- Fixed: Update Failed Could Not Update Post in the Database
- 403 Forbidden Access to this Resource on the Server is Denied!
- Fixed: Updating failed. The response is not a valid JSON response
- How to Remove Lazy Loading on Featured Image in WordPress
- How to Enable Persistent Object Cache on WordPress
- How to Fix Your Sitemap Appears to be an HTML Page | GSC
Leave a Reply