Should we use ob_start() in WordPress short code

It’s one way to do it.

I like it, because it allows you to write HTML code pretty easily and it makes it pretty obvious and easy to maintain. But it’s just opinion based, I guess.

It doesn’t harm your performance to much. You shouldn’t use output buffering to generate whole content of the site, because you want to start sending response to the browser as soon as possible, but this is not the case here…

You can also:

  • prepare the HTML output by concatenating strings (it’s harder to read and easier to make some html errors, IMHO),
  • use some “view” pattern