Write HTML in PHP with ob_start


The “OB” stands for “output buffer”, and essentially anything that comes after the “ob_start” and before the “ob_get_clean” is what’s returned in the function.

<?php
function theHTML( $attributes ) {
  ob_start(); ?>
   <h1> Fun with HTML!</h1>
   <p> This is PHP <?php echo esc_html($attributes['theThing']) ?> So great!</p>
   <?php return ob_get_clean();
}