How to Convert a Shortcode into ESI blocks?

I have created a PHP function for random text. Ideally, I would like to generate a random text on every page load or set it to a low TTL using ESI.

Is it possible to convert my custom shortcode into an ESI block?

function display_random_text() {
    // Array of texts
    $texts = [
        "Text 1",
        "Text 2",
        "Text 3",
        // Add more texts here
    ];

    // Randomly pick a text
    $random_text = $texts[array_rand($texts)];

    // Return the text
    return $random_text;
}
add_shortcode('random_text', 'display_random_text');

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer