最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Change headers for one custom PHP file

programmeradmin0浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论