TIL output buffering in PHP
POSTED ON:
TAGS: php
If you are outputting a lot of content, then you should use:
add_shortcode('my-shortcode', 'shortcode_function');
function shortcode_function( $args ) {
ob_start();
?>
<!-- your contents/html/(maybe in separate file to include) code etc -->
<?php
return ob_get_clean();
}
Without output buffering (the default), your HTML is sent to the browser in pieces as PHP processes through your script.
With output buffering, your HTML is stored in a variable and sent to the browser as one piece at the end of your script.
REFERENCE:
https://stackoverflow.com/a/2832179/4096078
https://stackoverflow.com/a/40500555/4096078
Related TILs
Tagged: php