This is for the wordpress developer out there whos been doing this for a long time, what i want is a suggestion on how to structure my code, what i want is a "separation of concern". Here is my set up right now, I have a page template that is a form, and i want a separate file to abstact the code from the template page. What im after is a maintainable code base.
Can you guys give me an suggestion, on how would you structure your code base, in a maintainable way. Any suggestion would be appreciated.
2
Answers
You’re looking for
get_template_part()
$slug
$name
In your case we could place your form in a template part, eg:
custom-page-form.php
then on the front end call it via<?php get_template_part( 'custom-page-form.php' ); ?>
.If you’re looking for kinda MVC, I would suggest you to use Timber. It provides twig template engine to handle your views, while logic behind it (models, controllers, config, etc) can be organized anywhere (but the endpoint must be functions.php).
Also, index.php must be present in theme, so it could be a start point for rendering your views. In fact, it could be any general WordPress template, but I prefer to keep only index.php.