Support » Plugin: LiteSpeed Cache » Modify HTML output (Output Buffer)

  • Hey!

    I have a user of one of our plugins (, and there happens something strange because our plugin modifies the content via ob_start, but the changes are only visible to logged-in users.

    I did some more research and found out that you offer custom filters to adjust the output buffer:

    Unfortunately, this does not help. I did a simple test with the following code in a custom plugin (no action, just plain in my-plugin.php):

    add_action('litespeed_buffer_after', function($content) {
        return str_replace('<html', '<html this-is-a-test1', $content);
    add_action('litespeed_buffer_before', function($content) {
        return str_replace('<html', '<html this-is-a-test2', $content);

    The result for logged-in users:

    The result for logged-out users:

    As you can see, the modifications are not visible to guests. I did already

    • try to completely purge the cache but no change.
    • deactivate all other plugins and switched theme to default WordPress theme
    ### wp-core ###
    version: 5.7.1
    site_language: en_GB
    user_language: en_GB
    timezone: Europe/London
    permalink: /%postname%/
    https_status: true
    multisite: false
    user_registration: 0
    blog_public: 0
    default_comment_status: open
    environment_type: production
    user_count: 888
    dotorg_communication: true
    ### wp-paths-sizes ###
    not relevant
    ### wp-dropins (1) ###
    advanced-cache.php: true
    ### wp-active-theme ###
    name: GeneratePress Child (generatepress_child)
    version: 0.1
    author: Tom Usborne
    parent_theme: GeneratePress (generatepress)
    theme_features: core-block-patterns, post-thumbnails, automatic-feed-links, post-formats, woocommerce, title-tag, html5, customize-selective-refresh-widgets, align-wide, responsive-embeds, custom-logo, menus, editor-style, wc-product-gallery-zoom, wc-product-gallery-lightbox, wc-product-gallery-slider, widgets
    theme_path: xxx
    auto_update: Disabled
    ### wp-parent-theme ###
    name: GeneratePress (generatepress)
    version: 3.0.3
    author: Tom Usborne
    theme_path: xxx
    auto_update: Disabled
    ### wp-themes-inactive (1) ###
    Twenty Twenty-One: version: 1.3, author: the WordPress team, Auto-updates disabled
    ### wp-plugins-active (52) ###
    a3 Lazy Load: version: 2.4.5, author: a3rev Software, Auto-updates disabled
    Ahrefs SEO: version: 0.8.1, author: Ahrefs, Auto-updates disabled
    Angell EYE Updater: version: 2.0.16, author: Angell EYE, Auto-updates disabled
    Anti-Spam by CleanTalk: version: 5.156, author: СleanTalk <>, Auto-updates disabled
    BBQ Firewall: version: 20210211, author: Jeff Starr, Auto-updates disabled
    Beaver Builder Pattern Backgrounds: version: 1.4.3, author: SiteSpot Dev, Auto-updates disabled
    Beaver Builder Plugin (Standard Version): version:, author: The Beaver Builder Team, Auto-updates disabled
    Booster for WooCommerce: version: 5.3.9, author: Pluggabl LLC, Auto-updates disabled
    Booster Plus for WooCommerce: version: 5.3.8, author: Pluggabl LLC (latest version: 5.3.9), Auto-updates disabled
    Classic Editor: version: 1.6, author: WordPress Contributors, Auto-updates disabled
    Disable Cart Fragments: version: 2.0, author: Optimocha, Auto-updates disabled
    Embed Sendy: version: 1.3.3, author: Ram Ratan Maurya, Auto-updates disabled
    Enable Media Replace: version: 3.5.0, author: ShortPixel, Auto-updates disabled
    Envato Market: version: 2.0.6, author: Envato, Auto-updates disabled
    Fetchify: version: 1.3.0, author: Fetchify, Auto-updates disabled
    Filester - File Manager Pro: version: 1.7.2, author: Ninja Team, Auto-updates disabled
    FooBox Image Lightbox: version: 2.7.16, author: FooPlugins, Auto-updates disabled
    FooGallery: version: 2.0.24, author: FooPlugins, Auto-updates disabled
    Format Media Titles: version: 1.0.0, author: David Gwyer, Auto-updates disabled
    GPLVault Update Manager: version: 3.4.1, author: GPL Vault, Auto-updates disabled
    GP Premium: version: 1.12.3, author: Tom Usborne, Auto-updates disabled
    Green Popups (formerly Layered Popups): version: 7.23, author: Halfdata, Inc. (latest version: 7.25), Auto-updates disabled
    Limit Login Attempts Reloaded: version: 2.21.1, author: Limit Login Attempts Reloaded, Auto-updates disabled
    LiteSpeed Cache: version: 3.6.4, author: LiteSpeed Technologies, Auto-updates disabled
    MailOptin - Lite: version:, author: MailOptin Team, Auto-updates disabled
    PayPal for WooCommerce: version: 2.5.7, author: Angell EYE, Auto-updates disabled
    PixelYourSite Microsoft UET (Bing): version: 2.1.0, author: PixelYourSite, Auto-updates disabled
    PixelYourSite Pinterest: version: 3.1.1, author: PixelYourSite, Auto-updates disabled
    PixelYourSite PRO: version: 8.2.1, author: PixelYourSite, Auto-updates disabled
    Popup Maker: version: 1.16.1, author: Popup Maker, Auto-updates disabled
    Popup Maker - Advanced Theme Builder: version: 1.2.0, author: Popup Maker, Auto-updates disabled
    Real Cookie Banner: version: 1.14.1-5648, author:, Auto-updates disabled
    Real Media Library: version: 4.13.4, author:, Auto-updates disabled
    Regenerate Thumbnails: version: 3.1.5, author: Alex Mills (Viper007Bond), Auto-updates disabled
    Regenerate Thumbnails Advanced: version: 2.4.0, author: ShortPixel, Auto-updates disabled
    Safe SVG: version: 1.9.9, author: Daryll Doyle, Auto-updates disabled
    Shortcode in Menus: version: 3.5.1, author: Gagan Deep Singh, Auto-updates disabled
    Simple Social Icons: version: 3.0.2, author: StudioPress, Auto-updates disabled
    Smart Slider 3 Pro: version:, author: Nextend, Auto-updates disabled
    Title and Nofollow For Links: version: 1.11, author: WPKube, Auto-updates disabled
    WooCommerce: version: 5.2.2, author: Automattic, Auto-updates disabled
    WooCommerce - Store Exporter Deluxe: version: 4.9, author: Visser Labs, Auto-updates disabled
    WooCommerce Advanced Bulk Edit: version:, author: George Iron, Auto-updates disabled
    WooCommerce Amazon Pay: version: 1.13.1, author: WooCommerce, Auto-updates disabled
    WooCommerce Multi Currency Premium: version: 2.1.11, author: VillaTheme, Auto-updates disabled
    WooCommerce Photo Reviews Premium: version:, author: VillaTheme, Auto-updates disabled
    WooCommerce Stripe Gateway: version: 5.1.0, author: WooCommerce, Auto-updates disabled
    WooCommerce Table Rate Shipping: version: 4.2.1, author: Bolder Elements, Auto-updates disabled
    WPC AJAX Add to Cart for WooCommerce: version: 1.3.2, author: WPClever, Auto-updates disabled
    WPC Product Bundles for WooCommerce (Premium): version: 5.5.3, author: WPClever, Auto-updates disabled
    Yoast Duplicate Post: version: 4.1.2, author: Enrico Battocchi & Team Yoast, Auto-updates disabled
    Yoast SEO: version: 16.1.1, author: Team Yoast, Auto-updates disabled
    ### wp-plugins-inactive (33) ###
    All-in-One WP Migration: version: 7.42, author: ServMask, Auto-updates disabled
    Blog2Social: Social Media Auto Post & Scheduler: version: 6.7.2, author: Blog2Social, Adenion, Auto-updates disabled
    Brindle's QuickPopPRO: version: 1.0.4, author: Brindle, Auto-updates disabled
    Complianz | GDPR/CCPA Cookie Consent: version: 5.0.1, author: Really Simple Plugins, Auto-updates disabled
    Connects - Sendy Addon: version: 2.1.4, author: Brainstorm Force, Auto-updates disabled
    Convert Plus: version: 3.5.18, author: Brainstorm Force, Auto-updates disabled
    Cookie Notice & Compliance for GDPR / CCPA: version: 2.0.4, author:, Auto-updates disabled
    Download Plugins and Themes from Dashboard: version: 1.7.1, author: Algoritmika Ltd, Auto-updates disabled
    Duplicator: version: 1.4.0, author: Snap Creek, Auto-updates disabled
    Error Log Monitor: version: 1.7, author: Janis Elsts, Auto-updates disabled
    FastDup: version: 1.2.1, author: Ninja Team, Auto-updates disabled
    Flying Pages by WP Speed Matters: version: 2.4.2, author: Gijo Varghese, Auto-updates disabled
    GDPR Cookie Consent: version: 2.0.1, author: WebToffee, Auto-updates disabled
    Integrately for WordPress: version: 0.1, author:, Auto-updates disabled
    Integration of Sendy with WooCommerce: version: 1.1, author: ProThoughts, Auto-updates disabled
    Klarna Order Management for WooCommerce: version: 1.6.7, author: klarna, krokedil, Auto-updates disabled
    Klarna Payments for WooCommerce: version: 2.4.3, author: krokedil, klarna, automattic, Auto-updates disabled
    NextScripts: SNAP Pro Upgrade Helper: version: 1.5.10, author: NextScripts, Auto-updates disabled
    NextScripts: Social Networks Auto-Poster: version: 4.3.20, author: NextScripts, Auto-updates disabled
    Ninja Forms: version: 3.5.4, author: Saturday Drive, Auto-updates disabled
    Ninja Popups: version: 4.7.5, author: ArsCode, Auto-updates disabled
    Post SMTP: version: 2.0.23, author: Yehuda Hassine, Auto-updates disabled
    Product Catalog Feed Pro by PixelYourSite: version: 5.1.1, author: PixelYourSite, Auto-updates disabled
    ShortPixel Adaptive Images: version: 2.2.1, author: ShortPixel, Auto-updates disabled
    ShortPixel Image Optimizer: version: 4.21.2, author: ShortPixel, Auto-updates disabled integration for WooCommerce: version: 1.6.2, author: dev team, Auto-updates disabled
    WooCommerce Abandoned Cart Recovery Premium: version:, author: VillaTheme, Auto-updates disabled
    WooCommerce Side Cart Premium: version: 2.4, author: XootiX, Auto-updates disabled
    Wordpress Pinterest Automatic: version: 4.14.2, author: ValvePress, Auto-updates disabled
    WP-Optimize - Clean, Compress, Cache: version: 3.1.8, author: David Anderson, Ruhani Rabin, Team Updraft, Auto-updates disabled
    WPC Fly Cart for WooCommerce: version: 3.0.0, author: WPClever, Auto-updates disabled
    WPC Smart Quick View for WooCommerce: version: 2.6.0, author: WPClever, Auto-updates disabled
    WPide: version: 2.5, author: WebFactory Ltd, Auto-updates disabled
    ### wp-media ###
    image_editor: FooGallery_Thumb_Image_Editor_Imagick
    imagick_module_version: 1650
    imagemagick_version: ImageMagick 6.7.2-7 2021-04-02 Q16
    file_uploads: File uploads is turned off
    post_max_size: 500M
    upload_max_filesize: 500M
    max_effective_size: 500 MB
    max_file_uploads: 20
    gd_version: bundled (2.1.0 compatible)
    ghostscript_version: 8.70
    ### wp-server ###
    server_architecture: Linux 2.6.32-954.3.5.lve1.4.80.el6.x86_64 x86_64
    httpd_software: LiteSpeed
    php_version: 7.4.15 64bit
    php_sapi: litespeed
    max_input_variables: 20000
    time_limit: 300
    memory_limit: 512M
    max_input_time: 300
    upload_max_filesize: 500M
    php_post_max_size: 500M
    curl_version: 7.74.0 OpenSSL/1.1.1j
    suhosin: false
    imagick_availability: true
    pretty_permalinks: true
    htaccess_extra_rules: true
    ### wp-database ###
    extension: mysqli
    server_version: 10.2.37-MariaDB-log-cll-lve
    client_version: mysqlnd 7.4.15
    ### wp-constants ###
    WP_HOME: undefined
    WP_SITEURL: undefined
    WP_PLUGIN_DIR: xxx
    WP_DEBUG: false
    WP_DEBUG_LOG: false
    SCRIPT_DEBUG: false
    WP_CACHE: true
    COMPRESS_SCRIPTS: undefined
    COMPRESS_CSS: undefined
    WP_LOCAL_DEV: undefined
    DB_CHARSET: utf8
    DB_COLLATE: undefined
    ### wp-filesystem ###
    wordpress: writable
    wp-content: writable
    uploads: writable
    plugins: writable
    themes: writable
    mu-plugins: writable

    Is there any limitation or is this a bug?

    Matthew 😊

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Hai Zheng⚡


    Hi Matthew,

    The buffer hook works for the logged-in users, that means the hook works. Each time when calling into that ob_start in that hook will be called always.

    In your case, I guess for guest users, it doesn’t run into that line at all. Maybe you need to check if LSCWP runs on that page or not. You can turn on debug log and see what logs tell.

    I tried your code

    add_action('litespeed_buffer_after', function($content) {
        return str_replace('<html', '<html this-is-a-test1', $content);

    in theme’s functions.php, works well for both logged in and guest users.

    Thread Starter Matthias Günter


    Hey @hailite !

    Thanks for your reply.

    In your case, I guess for guest users, it doesn’t run into that line at all. Maybe you need to check if LSCWP runs on that page or not.

    The user has the following plugin installed as you can see from the site-health export above: LiteSpeed Cache: version: 3.6.4, author: LiteSpeed Technologies. This is currently the only active plugin as I deactivated the others for testing purposes.

    You can turn on debug log and see what logs tell.

    I just enabled debugging in the LSCWP plugin and the following gets logged when opening the homepage as logged-in user:

    04/28/21 14:24:13.014 [ 1 0YC] 💓 ------GET HTTP/1.1 (HTTPS) /
    04/28/21 14:24:13.014 [ 1 0YC] Query String:
    04/28/21 14:24:13.014 [ 1 0YC] HTTP_REFERER:
    04/28/21 14:24:13.014 [ 1 0YC] Cookie _lscache_vary: admin_bar:1;logged-in:1;role:99;role_exclude_cache:1
    04/28/21 14:24:13.014 [ 1 0YC] LSCACHE_VARY_COOKIE: wmc_current_currency
    04/28/21 14:24:13.090 [ 1 0YC] [Ctrl] X Cache_control -> private ( logged in user )
    04/28/21 14:24:13.191 [ 1 0YC] [Router] get_role: administrator
    04/28/21 14:24:13.191 [ 1 0YC] [Core] ⛑️ bypass_optm: hit Role Excludes setting: administrator
    04/28/21 14:24:13.221 [ 1 0YC] [Ctrl] X Cache_control init on
    04/28/21 14:24:13.904 [ 1 0YC] [Core] Footer hook called
    04/28/21 14:24:13.913 [ 1 0YC] [Core] Footer check passed
    04/28/21 14:24:13.915 [ 1 0YC] [Ctrl] X Cache_control off - Role Excludes setting administrator
    04/28/21 14:24:13.915 [ 1 0YC] [Ctrl] X Cache_control -> no Cache
    04/28/21 14:24:13.915 [ 1 0YC] 💰 X-LiteSpeed-Cache-Control: no-cache
    04/28/21 14:24:13.915 [ 1 0YC] [Core] Footer check passed
    04/28/21 14:24:13.977 [ 1 0YC] End response

    And if I visit the same page as logged-out (guest) user, nothing is logged. Is this the correct behavior? For me it looks like the WordPress engine itself is not called when visiting the website as logged-out user.

    I also tried to put the exact same code you posted to the functions.php but it does not work, too. What else could I test?

    Matthew 😊

    Plugin Support Hai Zheng⚡


    I think that is bcos your guest page is cached 🙂 You need to purge before you can see the result, or easier way is to give the url you are visiting a QS, e.g.

    Thread Starter Matthias Günter


    Hi again!

    Thanks for your reply, and sorry for my wrong alert… LiteSpeed isn’t the cause, it is Anti Spam by Cleantalk.

    /Closed. 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.