Title: Modify HTML output (Output Buffer)
Last modified: April 27, 2021

---

# Modify HTML output (Output Buffer)

 *  Resolved [Matthias Günter](https://wordpress.org/support/users/mguenter/)
 * (@mguenter)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/modify-html-output-output-buffer/)
 * Hey!
 * I have a user of one of our plugins ([https://wordpress.org/plugins/real-cookie-banner/](https://wordpress.org/plugins/real-cookie-banner/)),
   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: [https://docs.litespeedtech.com/lscache/lscwp/api/#modify-output-buffer-before](https://docs.litespeedtech.com/lscache/lscwp/api/#modify-output-buffer-before)
 * 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:
 * ![](https://i0.wp.com/i.imgur.com/7Ewy8Oy.png?ssl=1)
 * The result for logged-out users:
 * ![](https://i0.wp.com/i.imgur.com/OBDAo7S.png?ssl=1)
 * 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
       author_website: https://tomusborne.com
       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
       author_website: https://tomusborne.com
       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 <welcome@cleantalk.org>, 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: 2.4.2.2, 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: 1.2.35.4, 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: devowl.io, Auto-updates disabled
       Real Media Library: version: 4.13.4, author: devowl.io, 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: 3.4.1.17, 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: 4.6.2.3, 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: 1.1.4.9, 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: Hu-manity.co, 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: Integrately.com, 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
       TrustMate.io integration for WooCommerce: version: 1.6.2, author: TrustMate.io dev team, Auto-updates disabled
       WooCommerce Abandoned Cart Recovery Premium: version: 1.0.6.2, 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 http://www.imagemagick.org
       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_CONTENT_DIR: xxx
       WP_PLUGIN_DIR: xxx
       WP_MEMORY_LIMIT: 256M
       WP_MAX_MEMORY_LIMIT: 512M
       WP_DEBUG: false
       WP_DEBUG_DISPLAY: true
       WP_DEBUG_LOG: false
       SCRIPT_DEBUG: false
       WP_CACHE: true
       CONCATENATE_SCRIPTS: false
       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?
 * Regards,
    Matthew 😊

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Support [Hai Zheng⚡](https://wordpress.org/support/users/hailite/)
 * (@hailite)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/modify-html-output-output-buffer/#post-14374934)
 * 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 [https://github.com/litespeedtech/lscache_wp/blob/dev/src/core.cls.php#L138](https://github.com/litespeedtech/lscache_wp/blob/dev/src/core.cls.php#L138)
   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](https://wordpress.org/support/users/mguenter/)
 * (@mguenter)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/modify-html-output-output-buffer/#post-14375217)
 * Hey [@hailite](https://wordpress.org/support/users/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 [79.219.221.194:63840 1 0YC] 💓 ------GET HTTP/1.1 (HTTPS) /
       04/28/21 14:24:13.014 [79.219.221.194:63840 1 0YC] Query String:
       04/28/21 14:24:13.014 [79.219.221.194:63840 1 0YC] HTTP_REFERER: https://staging.xxxxxxxx.com/wp-admin/admin.php?page=litespeed-toolbox
       04/28/21 14:24:13.014 [79.219.221.194:63840 1 0YC] Cookie _lscache_vary: admin_bar:1;logged-in:1;role:99;role_exclude_cache:1
       04/28/21 14:24:13.014 [79.219.221.194:63840 1 0YC] LSCACHE_VARY_COOKIE: wmc_current_currency
       04/28/21 14:24:13.090 [79.219.221.194:63840 1 0YC] [Ctrl] X Cache_control -> private ( logged in user )
       04/28/21 14:24:13.191 [79.219.221.194:63840 1 0YC] [Router] get_role: administrator
       04/28/21 14:24:13.191 [79.219.221.194:63840 1 0YC] [Core] ⛑️ bypass_optm: hit Role Excludes setting: administrator
       04/28/21 14:24:13.221 [79.219.221.194:63840 1 0YC] [Ctrl] X Cache_control init on
       04/28/21 14:24:13.904 [79.219.221.194:63840 1 0YC] [Core] Footer hook called
       04/28/21 14:24:13.913 [79.219.221.194:63840 1 0YC] [Core] Footer check passed
       04/28/21 14:24:13.915 [79.219.221.194:63840 1 0YC] [Ctrl] X Cache_control off - Role Excludes setting administrator
       04/28/21 14:24:13.915 [79.219.221.194:63840 1 0YC] [Ctrl] X Cache_control -> no Cache
       04/28/21 14:24:13.915 [79.219.221.194:63840 1 0YC] 💰 X-LiteSpeed-Cache-Control: no-cache
       04/28/21 14:24:13.915 [79.219.221.194:63840 1 0YC] [Core] Footer check passed
       04/28/21 14:24:13.977 [79.219.221.194:63840 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?
 * Regards,
    Matthew 😊
 *  Plugin Support [Hai Zheng⚡](https://wordpress.org/support/users/hailite/)
 * (@hailite)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/modify-html-output-output-buffer/#post-14375346)
 * 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. [https://domain.com/?xx](https://domain.com/?xx)
 *  Thread Starter [Matthias Günter](https://wordpress.org/support/users/mguenter/)
 * (@mguenter)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/modify-html-output-output-buffer/#post-14383332)
 * 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)

The topic ‘Modify HTML output (Output Buffer)’ is closed to new replies.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Matthias Günter](https://wordpress.org/support/users/mguenter/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/modify-html-output-output-buffer/#post-14383332)
 * Status: resolved