2016-04-07 213 views
1

如何修改HTTP响应标头并删除WordPress 4.4.2中的“链接”和“X-Pingback”?在WordPress中修改HTTP响应标头

仅在.htaccess中或在functions.php中?

请不要与文件头部区域混淆!

回答

0

添加到您的functions.php文件:

function remove_unwanted_headers($headers) { 
    unset($headers['X-Pingback']); 
    unset($headers['Link']); 
    return $headers; 
} 

add_filter('wp_headers', 'remove_unwanted_headers'); 
+0

这种解决方案只能在首页上 - 而不是在其他网站上。我使用起源框架。 – jMike

+0

你使用缓存吗?如果您的网站通过插件或第三方缓存系统提供缓存页面,此筛选器将不允许您修改标题。缓存页面将在您的wp_headers过滤之前提供。 – Ryan

+0

我只在.htaccess中使用浏览器缓存。但是我在浏览器中关闭了缓存。在其他答案的评论中看到我的解决方案! – jMike

3
/* Remove X-Pingback in the HTTP header */ 

add_filter('wp_headers', function($headers) { 

unset($headers['X-Pingback']); 

return $headers; 

}); 

这(AITpro的解决方案)的作品对我来说,除去在HTTP头中的链接REST API:

/*删除HTTP标头中Rest API的链接*/

remove_action('template_redirect','rest_output_link_header',11,0);

请检查链接[https://wordpress.org/support/topic/wp-44-remove-json-api-and-x-pingback-from-http-headers][1]

+0

链接已损坏;重定向到https://wordpress.org/support/ – jMike

+0

这会删除 - 链接:http:// /wp-json />; rel =“https://api.w.org/” - 这里 – jMike

+0

对不起,请检查这个https://wordpress.org/support/topic/wp-44-remove-json-api-andx -ping-from-http-headers @jMike –

0

为WordPress 4.9.1。 在你的主题的functions.php:

//remove Link header for rest api 
remove_action('template_redirect', 'rest_output_link_header', 11, 0); 
//remove Link header for shortlink 
remove_action('template_redirect', 'wp_shortlink_header', 11, 0); 
//remove X-Pingback header 
add_filter('pings_open', '__return_false'); 
// Optional. Disable xmlrpc 
add_filter('xmlrpc_enabled', '__return_false'); 

更多的过滤器和行动/wp-includes/default-filters.php