簡體   English   中英

如何在 Wordpress 中插入 Last-Modified HTTP-header?

[英]How to insert Last-Modified HTTP-header in Wordpress?

該站點不會在其響應中發送 Last-Modified 標頭。

我知道我應該插入類似header("Last-Modified: " . the_modified_date()); 但是哪里?

“上次修改”的 WordPress 插件對我有用。 http://wordpress.org/extend/plugins/header-last-modified/

它需要在 wp-includes/template-loader.php 中進行更改,因此在更新 WordPress 核心時要小心。

這對我的所有帖子都有效 - 添加到主題 functions.php 文件中:

add_action('template_redirect', 'theme_add_last_modified_header');
function theme_add_last_modified_header($headers) {
    global $post;
    if(isset($post) && isset($post->post_modified)){
        $post_mod_date=date("D, d M Y H:i:s",strtotime($post->post_modified));
        header('Last-Modified: '.$post_mod_date.' GMT');
     }
}

編輯 wp-config.php 將其插入到文件末尾 ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM