Is there any way of defining a Page Template from some function/filter/hook, without having any .php file containing the comment at the top of the page to declare the Template Name?
For example, instead of doing this:
some-custom-page-template.php
/**
* Template Name: Some Custom Page Template
*/
another-custom-page-template.php
/**
* Template Name: Another Custom Page Template
*/
I wonder if I can do something like:
functions.php
wp_some_function_to_define_templates( 'Some Custom Page Template' );
wp_some_function_to_define_templates( 'Another Custom Page Template' );
EDIT: I'm writing a complex and kind of experimental WP theme - It is as Object-Oriented as WP lets it to be, I have Controller classes to decide what to display in each page, DAO classes to retrieve data from DB, Twig templates to generate the views and so on...
I've spreaded the code so much, that my Page Templates have become just a line of code where I call some Controller and let it do the job, to finally render a Twig template. So I decided to move that call to the Controller, to inside the template_include
filter, so that I don't even need to put any code in the Page Templates...
I might get rid of Page Templates, but I still need them to group pages somehow, to set some Advanced Custom Fields groups for them, etc...
So I ended up with about 15 PHP files that contain only a comment at the top with some Template Name, which is exactly what I'd like to avoid by defining those templates from some function...
Am I trying to reinvent the wheel? Maybe in some sense, but I think it's becoming a really cool theme, very maintenable and modifiable...