How do I make WordPress return JSON on Nginx?
In my wordpress, Ajax calls return <?php JSON
instead just plain JSON
.
The site works just fine, except for admin-ajax calls.
TechInfo:
WordPress 4.5
PHP 5.6.11-1ubuntu3.1 (fpm-fcgi)
nginx version: nginx/1.9.3 (Ubuntu)
Headers sniff:
Request URL:http://SERVER/wp-admin/admin-ajax.php
Request Method:POST
Status Code:200 OK
Remote Address:IP:80
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://SERVER
Cache-Control:no-cache, must-revalidate, max-age=0
Connection:keep-alive
Content-Type:application/json; charset=UTF-8
Date:Tue, 26 Apr 2016 06:44:17 GMT
Expires:Wed, 11 Jan 1984 05:00:00 GMT
Pragma:no-cache
Server:nginx/1.9.3 (Ubuntu)
Transfer-Encoding:chunked
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Robots-Tag:noindex
Request Headers
view source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,pl;q=0.6
Connection:keep-alive
Content-Length:107
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:REDACTED ;)
Host:SERVER
Origin:http://SERVER
Referer:http://SERWER/wp-admin/media-new.php
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data
view source
view URL encoded
data[wp-auth-check]:true
interval:60
_nonce:32b36eaa97
action:heartbeat
screen_id:media
has_focus:false
NGINX
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
Just to close this topic.
The problem was NO COMMENTS in functions.php file
After I added the following to
functions.php
, the problem disappeared.Check if you wordpress files were not compromised. You probably have some modification made in core WordPress files that adds ”
Do fresh install of WordPress files and check it it still exists.
All modification to wordpress should be done in theme folder or plugins.
I problem still occurs try to disable all plugins and turn on one by one. It is possible that one of plugins is messing up.