What is the point of using the front-page.php template? [closed]

You would use the front-page.php template because it allows to have custom content and layout for your website’s static front page. You can edit content on your static front page from inside the WordPress admin if the front-page.php template contains the the_content() template tag or similar. It really depends on what your content and presentation … Read more

Is there a way to have WordPress autodetect page templates in the page-templates directory and any sub-folders?

You should be able to do this with the theme_templates filter (see the get_page_templates() function). What you need is a function that walks through the sub-directories and returns all the page templates. Then you hook it into that filter. You could create a function based on get_post_templates(), replacing the call to get_files() with a function … Read more

Create Page with Template File from Plugin Folder

It is probably wp_insert_post can’t recognize your template. You need to include it in the list of the templates. function wpse410645_add_plugin_template( $page_templates ) { $page_templates[plugin_dir_path( __FILE__ ) . ‘/templates/mytemplate.php] = ‘My Template Name’; return $page_templates; } add_filter( ‘theme_page_templates’, ‘wpse410645_add_plugin_template’ );