Home > CMS Tutorial > WordPress > body text

Let's talk about how WordPress sends native HTTP headers to the page through headers

藏色散人
Release: 2023-02-22 11:49:58
forward
1826 people have browsed it

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.

Let's talk about how WordPress sends native HTTP headers to the page through headers

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' );
Copy after login

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!

Related labels:
source:ludou.org
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template