如果要使用模板文件,需要编写functions.php.
挂钩是theme_page_templates.
像这样
* @param array $post_templates Array of page templates. Keys are filenames, values are translated names.
* @return array Filtered array of page templates.
*/
function makewp_exclude_page_templates($post_templates)
{
if (version_compare($GLOBALS[\'wp_version\'], \'4.7\', \'<\')) {
unset($post_templates[\'templates/my-full-width-post-template.php\']);
}
return $post_templates[\'page-templates/blog.php\'];
}
add_filter(\'theme_page_templates\', \'makewp_exclude_page_templates\');