Tag: Shortcodes

Understanding PHP Output Buffering, and Why It’s Great for Shortcodes

When I was learning PHP, one of the first things that really stumped me was the difference between code that created output and code that didn’t. I knew, vaguely, that things that had an echo statement in PHP meant something important, but that was about it. What I now get, is that echo statements are essentially output generators: they “leak out” of other PHP code. They create meaningful, visible output, most other PHP code doesn’t. Most other PHP code will transform data, but it won’t show it to users. But what we’re focusing on here is that you can actually capture, store, and use echoed output. This is called “output buffering” and it initially confused me and then blew my mind.