Creating a custom template loader
First, we have to add a function to the WP_Theme
class of the plugin to include the template loader file, as shown in the following code. Also, we have to update the constructor to call the template_init
function upon plugin initialization:
public function template_init() { include_once 'class-wpwa-template-loader.php'; }
Create a new file named class-wpwa-template-loader.php
inside the plugin class to implement the template loader. Let's implement the loader by creating a new class named WPWA_Template_Loader
inside the class-wpwa-template-loader.php
file:
class WPWA_Template_Loader{ private $template_dir; public function __construct(){ $this->template_dir = "templates"; } public function render($name,$data = array() ...
Get WordPress Web Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.