Loader That assists with adding post templates to a WordPress website.
composer require underpin/post-template-loader
This plugin uses a built-in autoloader, so as long as it is required before Underpin, it should work as-expected.
require_once(__DIR__ . '/underpin-post-templates/post-templates.php');
- Install Underpin. See Underpin Docs
- Register new post templates as-needed.
A very basic example could look something like this.
\Underpin\underpin()->post_templates()->add( 'template', [
'name' => 'Template Name', // Shows in dropdown
'template' => 'template-name' // Shows when post template is fetched, and in REST
] );
Alternatively, you can extend post template
and reference the extended class directly, like so:
underpin()->post_templates()->add('key','Namespace\To\Class');