Register WordPress page templates via functions file

Using the theme_page_templates filter we can registered a custom template that appears in the page attributes template dropdown without having to create a template file

Recently when creating an Angular theme using the WordPress REST API, I came across a situation where i needed to set the page template but had no need for the php template file.

Using the theme_page_templates filter we can registered a custom template that appears in the page attributes template dropdown.

/**
 * Register Homepage Template
 */
function jc_register_page_templates($templates){
  $templates['home'] = 'Homepage';
  return $templates;
}
add_filter('theme_page_templates', 'jc_register_page_templates');

Leave a Reply

Fields marked with an * are required to post a comment