搜索
首页CMS教程WordPress聊聊WordPress怎么通过header给页面发送原生HTTP头

本篇文章给大家带来了关于WordPress的相关知识,其中主要跟大家聊一聊WordPress怎么通过header给页面发送原生HTTP头,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

聊聊WordPress怎么通过header给页面发送原生HTTP头

在PHP中,我们可以用 header 函数来发送原生 HTTP 头,但在WordPress中怎么发送HTTP 头呢?

方法一:自己写代码

将下面的代码放到当前主题的functions.php中即可:

/**
*  在用户登陆的情况下,给前台所有页面添加不缓存的 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' );

方法二:用插件

HTTP Headers:https://wordpress.org/plugins/http-headers/

HTTP headers to improve web site security:https://wordpress.org/plugins/http-security/

推荐学习:《WordPress教程

以上是聊聊WordPress怎么通过header给页面发送原生HTTP头的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:ludou。如有侵权,请联系admin@php.cn删除
使用WordPress管理内容有多容易?使用WordPress管理内容有多容易?May 09, 2025 am 12:11 AM

WordPressiser-FrightlyDuetLoitsIntuitiveInterfaceAndcms,whosparateContentFromDesign.itoffersArichTextedextEditorforeasyContentCreationAndialibraryFororRaryFororRory.itsflexeNhangedBancedBynhangedBynHangedBynumereNumerSandeMesandPlugins,elloverSandplugins,elloverOverUseCanimpActpercrance

WordPress如何在业务环境中使用?WordPress如何在业务环境中使用?May 08, 2025 am 12:04 AM

1)ITSUPPORTSE-CommerceWithPluginSlikeWooCommerce,允许ProductManagementAndAndPaymentProcessing.2)ITSERVESASASASACMSACMSACMSMSACMSMSACMSMASTRATATEBLOGS,增强SeoAndEngagement.3)

哪些类型的网站不适合WordPress?哪些类型的网站不适合WordPress?May 07, 2025 am 12:10 AM

WordPressIsnotIdeAlforHigh-TrafficWebsites,customandCompleXapplications,Security-SensitiveApplications,Real-TimedataProcessing,AndhighlyCustomizedUserInterfaces.forhigh-Trafficsites,USENENEXT.JSORXOLCT.JSORXORX.JSORCUSTOMSOMOLTICTS; forCompleXapplications; forcomplexapplications; optfordjangoorrub

您可以使用WordPress构建博客吗?您可以使用WordPress构建博客吗?May 06, 2025 am 12:03 AM

Yes,youcanbuildablogwithWordPress.1)ChoosebetweenWordPress.comforbeginnersorWordPress.orgformorecontrol.2)Selectathemetopersonalizeyourblog'slook.3)Usepluginstoenhancefunctionality,likeSEOandsocialmediaintegration.4)Customizeyourthemewithsimplecodetw

WordPress作为CMS平台的安全程度如何?WordPress作为CMS平台的安全程度如何?May 05, 2025 am 12:01 AM

WordPressCanbeseCureifManagedProperly.1)keepthewordPressCoreUpdatedTopatchVulnerabilities.2)vetandupdatepluginsandthemesfromreputables.3)EnforcestrongpasseTSandusetWordssandusetWordwordwo-factorauthenticaliation.4)

您可以使用WordPress CMS构建哪种网站?您可以使用WordPress CMS构建哪种网站?May 04, 2025 am 12:06 AM

WordPressCanbuildVariousTypesofwebsites:1)个人博客,EasyTosetUpWithTheMesandPlugins.2)BusinessWebsites,使用drag-and-dropbuilders.3)e-commercePlatforms,forwoocommerceforsemcommerceforseameamseamelesssites.4)communitySites.4)conduction.4)使用bbudicatipration

将WordPress用作CMS的优缺点是什么?将WordPress用作CMS的优缺点是什么?May 03, 2025 am 12:09 AM

WordPressisapowerfulCMSwithsignificantadvantagesandchallenges.1)It'suser-friendlyandcustomizable,idealforbeginners.2)Itsflexibilitycanleadtositebloatandsecurityissuesifnotmanagedproperly.3)Regularupdatesandperformanceoptimizationsarenecessarytomainta

WordPress与其他流行的CMS平台相比如何?WordPress与其他流行的CMS平台相比如何?May 02, 2025 am 12:18 AM

WordPressExcccelineaseeandaDaptability,MakeitiTidealForBeginnersandsMallTomedium-SizedBusinesses.1)siseofuse:wordpressisuser-Frylyly.2)安全:drupalleadswithstrongsecurityfeatures.3)性能:performance:performance formation:ghandoffersefersefersefersefersefersefersefersexcellentperformanceeduetonodeutonode.jsorscor.jssor.jjsy.jjsy.jjsy.4)4)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具