[wp-hackers] Sending a Last-Modified header with HTML pages

Brian Layman Brian at TheCodeCave.com
Tue Nov 14 21:11:25 GMT 2006

> We're currently preparing to convert our blog to WordPress and
> discovered that it isn't emitting Last-Modified headers for page views.
> Can anyone provide some context on why WP has this behavior?
The quick answer would be: Plugins and themes.

In a general release, there are way to many ways for any particular WP page
to change.

Plugins, user settings and theme switchers all work against WP delivering a
standard page. 

However, WP DOES use Last-Modified for all feeds.  There even two detection
methods, for the last modified date, based upon whether or not the feed
includes comments. 

If you take a look at the function Send_Headers with in
wp-includes/classes.php, you'll see the support for Last-Modified.

If your page is really static, (and looking at your blog it is) you can
easily fix the problem by MOVING (not copying) this code:
       // We're showing a feed, so WP is indeed the only thing that last
       if ( $this->query_vars['withcomments'] )
           $wp_last_modified = mysql2date('D, d M Y H:i:s',
get_lastcommentmodified('GMT'), 0).' GMT';
           $wp_last_modified = mysql2date('D, d M Y H:i:s',
get_lastpostmodified('GMT'), 0).' GMT';
       $wp_etag = '"' . md5($wp_last_modified) . '"';
       @header("Last-Modified: $wp_last_modified");
       @header("ETag: $wp_etag");

up right after the first line:
@header('X-Pingback: '. get_bloginfo('pingback_url'));

Another question might be, why don't we have a hook right there in
send_header.  It would be a good place for one.  Is there an equivelent hook
somewhere else?

Brian Layman

More information about the wp-hackers mailing list