A simple class that allows registering WordPress Page templates from plugins.
composer require codelight-eu/page-templates
It's super simple. Run this somewhere in your WordPress plugin:
<?php
$pageTemplates = new Codelight\PageTemplates\PageTemplates();
$pageTemplates->addTemplate(
WP_PLUGIN_DIR . '/my-custom-plugin/templates/my-awesome-template.php',
"My Awesome Template's Human-Readable Name"
);
This adds the template to your WordPress site's Page edit interface.
The addTemplate()
function takes two params:
/**
* Add a new custom template.
*
* @param $file string Full path to the template file
* @param $name string Human-readable template name
*/
public function addTemplate($file, $name)
{
$this->templates[$file] = $name;
}
This library was adapted from http://www.wpexplorer.com/wordpress-page-templates-plugin/