How we will add template files for our plugins

This is how we can add template files directly from our plugin directory. We'll probably develop them in the theme folder first and then move them to the plugin folder.

add_filter
( 'template_include', 'my_plugin_templates' ); function my_plugin_templates( $template ) { $post_types = array( 'project' ); if ( is_post_type_archive( $post_types ) && ! file_exists( get_stylesheet_directory() . '/archive-project.php' ) ) $template = 'path/to/list/template/in/plugin/folder.php'; if ( is_singular( $post_types ) && ! file_exists( get_stylesheet_directory() . '/single-project.php' ) ) $template = 'path/to/singular/template/in/plugin/folder.php'; return $template; }