This article brings you relevant knowledge about WordPress. It mainly talks about how WordPress sends native HTTP headers to the page through headers. Friends who are interested can take a look below. I hope it will be helpful to everyone. help.
In PHP, we can use the header function to send native HTTP headers, but how to send HTTP headers in WordPress?
Method 1: Write the code yourself
Put the following code into functions.php of the current theme:
/** * 在用户登陆的情况下,给前台所有页面添加不缓存的 Cache-Control 头 */ function ludou_http_headers() { // 判断用户是否登陆,并且是在非后台(前台)页面 if(is_user_logged_in() && !is_admin()) { // php的header函数发送HTTP 头 header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); } } /* WordPress hook * 第一个参数值 wp 是action动作名称,文档:https://codex.wordpress.org/Plugin_API/Action_Reference/wp * 第二个参数值 ludou_http_headers 是上面的函数名称,自己取名 */ add_action( 'wp', 'ludou_http_headers' );
Method 2: Use plug-in
HTTP Headers: https://wordpress.org/plugins/http-headers/
HTTP headers to improve web site security: https: //wordpress.org/plugins/http-security/
Recommended study: "WordPress Tutorial"
The above is the detailed content of Let's talk about how WordPress sends native HTTP headers to the page through headers. For more information, please follow other related articles on the PHP Chinese website!