Home / Admin / Exclude Cache Page
Duplicate Snippet

Embed Snippet on Your Site

Exclude Cache Page

Exclude caching pages based on URL slugs.

Code Preview
php
<?php
// Exclude Cache Page / Kiri Vadivelu / 2026
function exclude_cache_page() {
    $excluded_urls = array(
        '/client-portal/',
        '/checkout/',
        '/cart/',
    );
    $uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    foreach ( $excluded_urls as $url ) {
        if ( strpos( $uri, $url ) !== false ) {
            if ( ! defined( 'DONOTCACHEPAGE' ) ) {
                define( 'DONOTCACHEPAGE', true );
            }
            nocache_headers();
            return;
        }
    }
}
add_action( 'template_redirect', 'exclude_cache_page' );   

Comments

Add a Comment