• Resolved the_lar

    (@the_lar)


    Hi,

    I have a form field on my page and need to exclude a data attribute on the input from caching. Here’s my code so far:

    On my page:

    $exclude = apply_filters( 'litespeed_esi_url', 'my_esi_block', 'Custom ESI block' );
    
    $html = <<<HTML
    <input id="sc-fbf-reg-tyre-search--size-postcode_{$id}" type="text" class="sc-fbf-reg-tyre-search__form-field tyre-size postcode" data-search_postcode="{$exclude}" disabled />
    HTML;
    echo $html;

    In my filters.php:

    function my_esi_block_esi_load()
    {
        #do_action( 'litespeed_control_set_ttl', 300 );
        do_action( 'litespeed_control_set_nocache' );
        echo "Hello world".rand (1,99999);
    }
    add_action( 'litespeed_esi_load-my_esi_block', '\App\my_esi_block_esi_load' );

    The problem I have is that upon viewing the resultant html, I am getting:

    <input id="sc-fbf-reg-tyre-search--size-postcode_" type="text" class="sc-fbf-reg-tyre-search__form-field tyre-size postcode" data-search_postcode="Hello world71492<!-- Block uncached by LiteSpeed Cache 5.4 on 2023-09-06 11:40:42 -->" disabled="">

    My basic question is how do I remove the HTML comment as obviously it’s not required in this context.

    Many thanks

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support qtwrk

    (@qtwrk)

    please try add define('LSCACHE_ESI_SILENCE', true); at top of your wp-config.php

    Thread Starter the_lar

    (@the_lar)

    Hi @qtwrk, thank you for the reply. We use roots/bedrock as our base so that composer manages all of our WordPress and Plugin updates, that means that wp-config.php will constantly get overwritten with updates, so we have a /config folder in the level above /public_html. I’ve tried adding Config::define('LSCACHE_ESI_SILENCE', true); to /config/application.php but it didn’t work. Adding to /public_html/wp/wp-config.php did work but this isn’t really maintainable going forward because as I said, it will keep getting overwritten

    Plugin Support qtwrk

    (@qtwrk)

    I am not sure how exactly is your structure , but bottom line , you must find a way to define() that constant before WP loads plugins

    maybe you can try use mu_plugin_loaded action , it seems fired in very early stage

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Litespeed ESI block – how to remove HTML comment?’ is closed to new replies.