Home / Admin / Cache Exclude Slug
Duplicate Snippet

Embed Snippet on Your Site

Cache Exclude Slug

Exclude caching posts based on URL slug using substring value match.

Code Preview
php
<?php
// Cache Exclude Slug / Kiri Vadivelu / 2026
function cache_exclude_slug() {
    // Match any URL that contains this substring
    $slug_fragment = '/category/'; // partial slug value
    if ( str_contains( $_SERVER['REQUEST_URI'], $slug_fragment ) ) {
        if ( ! defined( 'DONOTCACHEPAGE' ) ) {
            define( 'DONOTCACHEPAGE', true );
        }
    }
}
add_action( 'template_redirect', 'cache_exclude_slug' );  

Comments

Add a Comment