Are there any techniques to separate code and markup in WordPress?

I generally work with Python to create web apps and love how I can work separately with the code and presentation layers. I really like working with Jinja2. But, I sometimes have to work with WordPress for my clients. So, I wonder, if there are any ways to make developing for WordPress a less headache with all its header.php, index.php and footer.php as well as all other pieces that may join together well or may not. Are there any suggestions to make it more convenient?

Related posts

Leave a Reply

4 comments

  1. Agreed with Denis, WordPress simply is spaghetti, and there’s nothing you can do about that. Nonetheless, if you’re writing your own code for WordPress (we make themes and plugins for our customers), there’s nothing stopping you from splitting the concerns out into different files, and we found that it’s much easier to maintain that way. You’ll still have to coop with situations where WordPress expects vanilla PHP files, but at least our code looks decent 😉

  2. Sadly not. And best I’m aware, there aren’t any immediate plans to adopt a more MVC-like architecture.

    Some have tried to add Smarty on top and such, but doing so mostly adds bloat on top of the existing bloat. (The WP templating engine frequently consists of batches of function calls that call each other, each with their own set of plugin filters and global variables.)

  3. I find putting all reusable template items as separate php, and including presentation logic as a theme function/object and business logic in a plugin in an okay way to separate concerns as such objects/functions are always available if loaded correctly. The template parts do save significant time if you use particular code all the time (like breadcrumbs for example).
    I know its not satisfactory, but separation of concerns is possible.