admin管理员组

文章数量:1429562

I have a server.php file that I wish to host on the same server as my Wordpress site, that is required to send a POST message with a header of Content-type: application/json.

Wordpress is preventing me to use <?php header("ContentType : application/json"); ?> and doing so, it redirects to some file on https://site/wp-json/, which is not what I want.

Tried using the below code in the same file, but then it returns HTTP 500 Internal server error:

function changeHeaders($headers) {

    $headers['Content-Type'] = 'application/json';
    return $headers; 
}

add_filter('wp_headers', 'changeHeaders');

How do I change the headers just for that file without the need to create a subdomain or host it on another server without Wordpress?

本文标签: Change headers for one custom PHP file