WordPress.org

Forums

[resolved] WP Super Cache doesn't cache 404s... should it? (8 posts)

  1. Simon Wheatley
    Code for the People
    Posted 5 years ago #

    Hi,

    Just wondering what the thinking behind WP Super Cache not caching 404 responses is? I can see no generic disadvantage to it doing so, although I suppose some themes might provide "helpful" dynamically generated 404 error pages. Perhaps a filter or option to allow caching of 404s might be handy?

    Here's a patch I made to WPSC to allow caching of 404 requests:

    Index: /Users/simon/Projects/SF/trunk/site/wp-content/plugins/wp-super-cache/wp-cache-phase2.php
    ===================================================================
    --- /Users/simon/Projects/SF/trunk/site/wp-content/plugins/wp-super-cache/wp-cache-phase2.php	(revision 2566)
    +++ /Users/simon/Projects/SF/trunk/site/wp-content/plugins/wp-super-cache/wp-cache-phase2.php	(working copy)
    @@ -251,7 +251,7 @@
    
     	/* Mode paranoic, check for closing tags
     	 * we avoid caching incomplete files */
    -	if( $wp_cache_404 ) {
    +	if( $wp_cache_404 && !apply_filters( 'supercache_404s', true ) ) {
     		$new_cache = false;
     		$buffer .= "\n<!-- Page not cached by WP Super Cache. 404. -->\n";
     	}

    S

  2. Donncha O Caoimh
    Member
    Posted 5 years ago #

    Just added that to trunk as the "wpsupercache_404" filter, but reversed the filter so that 404 pages are still not cached by default. Return true to supercache those pages. Thanks!

  3. Simon Wheatley
    Code for the People
    Posted 5 years ago #

    Awesome, thanks Donncha!

  4. dbasulto
    Member
    Posted 5 years ago #

    So in order to get this to work I should add

    <?php add_filer ('wpsupercache_404', '', '', 'true' ); ?>

    or

    apply_filters('supercache_404s', true );

    to functions.php?

  5. Donncha O Caoimh
    Member
    Posted 5 years ago #

    You need to use add_filter(), but not in the way you've tried above. That's not how filters work. Google for "WordPress add_filter" and you'll find out all you need to know!

  6. dbasulto
    Member
    Posted 5 years ago #

    thanks, I´m reading that at the Codex.

  7. dbasulto
    Member
    Posted 5 years ago #

    I went trough the Codex but couldn´t figure out how to do this so I could cache 404 pages... any help?

  8. Donncha O Caoimh
    Member
    Posted 5 years ago #

    This should do it:

    add_action ( 'wpsupercache_404', create_function ( '$a' , "return true" ) );

Topic Closed

This topic has been closed to new replies.

About this Topic