apply_filters( ‘wp_template_enhancement_output_buffer’, string $filtered_output, string $output )

In this article

Filters the template enhancement output buffer prior to sending to the client.

Description

This filter only applies the HTML output of an included template. This filter is a progressive enhancement intended for applications such as optimizing markup to improve frontend page load performance. Sites must not depend on this filter applying since they may opt to stream the responses instead. Callbacks for this filter are highly discouraged from using regular expressions to do any kind of replacement on the output. Use the HTML API (either WP_HTML_Tag_Processor or WP_HTML_Processor), or else use DOM\HtmlDocument as of PHP 8.4 which fully supports HTML5.

Do not print any output during this filter. While filters normally don’t print anything, this is especially important since this applies during an output buffer callback. Prior to PHP 8.5, the output will be silently omitted, whereas afterward a deprecation notice will be emitted.

Important: Because this filter is applied inside an output buffer callback (i.e. display handler), any callbacks added to the filter must not attempt to start their own output buffers. Otherwise, PHP will raise a fatal error: “Cannot use output buffering in output buffering display handlers.”

Parameters

$filtered_outputstring
HTML template enhancement output buffer.
$outputstring
Original HTML template output buffer.

Source

$filtered_output = (string) apply_filters( 'wp_template_enhancement_output_buffer', $filtered_output, $output );

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.