• Resolved sitemacker

    (@ahmad7091)


    Hello
    When I use Esi for shortcodes, instead of displaying the shortcode on the site itself, the shortcode is written.

    In fact, the shortcode itself is displayed on the site with a space. like this:

    echo do_shortcode(‘[esi my_shortcode]’);

    when i check frontend i see:

    [my_shortcode ]

    there is a space after my_shortcode

    Lightspeed and all plugins are updated. I have read all the related articles for it.cache and esi are enabled.
    The code below also shows the answer of its activation:

    <?php
    require( './wp-load.php' ); $esi_status = apply_filters( 'litespeed_esi_status', false );
    var_dump($esi_status);
Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter sitemacker

    (@ahmad7091)

    somebody can help pls?

    Plugin Support qtwrk

    (@qtwrk)

    did it work on without esi

    I just tested below

    function test_shortcode($atts) {
        $atts = shortcode_atts(
            array(
                'show_date' => 'false',
            ),
            $atts,
            'test_sc'
        );
    
        if ($atts['show_date'] === 'true') {
            $current_date = date('Y-m-d H:i:s');
            $message .= ' generation time: ' . $current_date . '.';
        }
    
        return $message;
    }
    add_shortcode('test_sc', 'test_shortcode');

    and

    <?php
    require( './wp-load.php' );
    echo do_shortcode('[esi test_sc show_date="true" ttl="0"]');

    it works

    Thread Starter sitemacker

    (@ahmad7091)

    Unfortunately, the code you sent did not work for me. I had the same error as my code.
    When I remove ESI from the beginning of the shortcode, it works correctly, and when I add ESI, it writes the shortcode itself.

    your shortcode with esi (A space is at the end of the shortcode, not the beginning. The language of the site was rtl and I wrote it wrong in img):

    your shortcode without esi

    Plugin Support qtwrk

    (@qtwrk)

    an old memory suddenly strikes me that I have seen such case before

    this will happen if there is certain plugin that disables LiteSpeed Cache plugin like perfmatters or something else I don’t recall immediately

    please try grab some logs upon the visit

    Thread Starter sitemacker

    (@ahmad7091)

    Thank you for your help.
    Only Lightspeed plugin is installed on the site. I have coded all parts of the site myself. Yesterday I changed all the codes of the site so that I can use esi. But unfortunately it didn’t work ??

    Now, on another site on the same server, which I checked, this feature works correctly and it seems that the problem is with my codes, which does not work on shortcodes.

    Please answer these questions if possible:

    I only need the ESI feature to not cache a div on the page. Is there no other way? Can’t be excluded through class or ID?

    Should a code or hook be entered in the theme so that I can implement this feature?
    I don’t call the wp_head() and wp_footer() codes in my form and I don’t need them. Of course, I don’t think the problem is with these hooks.

    Can you send me a sample code with function not shortcode? Something other than those codes inside the Lightspeed site(doc). with the fewest lines of code possible.

    Tnx

    Plugin Support qtwrk

    (@qtwrk)

    no , the way how page cache works , it caches by page as unit

    ESI could be a simplest way , otherwise you need to use ajax call to update it on client-side

    not exactly sure what do you mean by this question , it can be used on theme’s functions.php , as simple and quick example , or from a plugin

    for example this one: https://github.com/qtwrk/lscwp-esi-pv/blob/main/esi-post-view.php

    • This reply was modified 9 months, 2 weeks ago by qtwrk.
    Thread Starter sitemacker

    (@ahmad7091)

    I think it happens because I don’t use jQuery on my site (which is necessary for Ajax).

    Thank you for your time @qtwrk

    Plugin Support qtwrk

    (@qtwrk)

    huh ? no, it must be something else, esi doesn’t need JQ or any javascript or ajax

    Thread Starter sitemacker

    (@ahmad7091)

    Yes. I quickly read the text and did not see the word “otherwise” in the sentence “otherwise you need to use ajax call to update it on client-side”. It had nothing to do with Ajax and jQuery.
    there is ni log in error_log and I checked everything I could.

    I’ll temporarily disable the cache and try again later. If I find a problem, I will announce it on this page.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘esi for shortcodes’ is closed to new replies.