How to fix WordPress error Publishing failed. The response is not a valid JSON response.

Introduction

This error appeared to me on a test WP install I was working on.

When I tried to save a post in WordPress I've got this message: Publishing failed. The response is not a valid JSON response.

This looked really weird as I could not save any post or page which remained as drafts with "Auto Draft" title.

wordpress publishing failed valid json

Also I have noticed the top left WP logo was missing.

How to fix WP publishing failed error

After some research I've found out that this could be easily fixed by regenerating the permalinks.

So I logged in to WP admin and went to Settings > Permalinks and clicked on "Save Changes". But this did not fix the not valid JSON response error.

I have also found a suggestion to activate the Classic Editor plugin to fix this publishing error. But this did not work.

I checked more on my code, plugins (I thought it is a plugins conflict so I have deactivated all, but still no result) and I have also checked my .htaccess file.

I have my test install in a folder, not in the domain root. In my .htaccess file I've found that I had a code for the root file and another piece of code for the folder:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /test/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php [L]
</IfModule>

# END WordPress

I have deleted the top part and left only this:

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /test/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php [L]
</IfModule>

# END WordPress

The post editing error was fixed!

So, the solution for "Publishing failed. The response is not a valid JSON response." error is to delete the .htaccess file and regenerate it again by going to WP admin > Settings > Permalinks and click on "Save Changes" button.

In order to delete the .htaccess file, you need to login to your FTP and delete it from there. Only after that you will regenerate the permalinks.

Conclusion

This error could give you a headache, but if you follow the above tips you should be able to solve it. Good Luck!

Comments closed

Please contact me, if you have any questions or suggestions.