• Resolved swoolrich

    (@swoolrich)


    I have a couple of pages where I need to prevent cacheing as they have links to jpg files which change every 10 minutes. I’m using a child theme, I have created a custom page, and edited header.php in the child them to include this:

    <?php echo '<!-- page template = ' . basename( get_page_template() ) . ' -->'; ?>
    
    <?php
            if ( is_page_template( 'pilot-nocache.php' ) ) {
    
                    nocache_headers();
            }
    ?>
    
    <!-- Yoast Breadcrumbs -->
    <?php
    if ( function_exists('yoast_breadcrumb') ) {
    yoast_breadcrumb('
    <p id="breadcrumbs">','</p>
    ');
    }
    ?>
    
    <!-- Custom Header - End -->
    <?php tha_header_bottom(); // custom action hook ?>
    </header><!-- .site-header -->
    <?php tha_header_after(); // custom action hook ?>
    <div id="content" class="site-content">

    Is nocache_headers in the wrong place? Is there something more subtle to this?

    I have checked the template name in the code is correct!

    • This topic was modified 7 years, 9 months ago by swoolrich. Reason: Mistake in code
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, wrong place. Not in the <header> section of HTML output, it needs to be called before WP outputs TCP/IP headers. “Header” is an unfortunately ambiguous term. There are several others, don’t get me started ??

    The latest possible action before WP sends TCP/IP headers is “parse_request”. With this action your callback is passed the query vars that WP came up with from parsing the request. It will not have which template will be used, but there ought to be enough data in the query vars to determine whether caching should be disabled or not.

    You can confirm the correct headers are sent by using your browser’s developer tools, specifically the network tool. Load the page, then click on the initial request line to see the headers sent. Each browser’s way of getting to the headers may be slightly different, but that’s the general approach.

    Thread Starter swoolrich

    (@swoolrich)

    I wish I could find parse_request…. I’ve looked in my child theme and in the parent theme to no avail. Fortunately I’ve changed a Jetpack setting which seems to have resolved the problem.

    • This reply was modified 7 years, 9 months ago by swoolrich.
    • This reply was modified 7 years, 9 months ago by swoolrich.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prevent a page caching’ is closed to new replies.