Is it possible to have a custom page template in a different folder?
I’m setting up a little framework for WordPress that I can use over and over for themes and just for the sake of being tidy I want to put custom page templates inside a different folder rather than the root of the theme directory.
How would one go about this?
WordPress uses
get_page_template()
to determine the template file to use which can be altered by filters:I wanted the same functionality as this. It seemed as though it is impossible to do this without core changes, but i managed to get it working – in a slightly different way.
Create a page template in the root of your Theme, call it themename-page-loader.php
In that file put the following code:
Then in your theme root, create a folder for your pages, in this example i called mine views. Inside this folder you put your page templates, just make sure the file name is the same as the page name you set in
WP_ADMIN
.