I have created a template file for a custom page inside wordpress plugin directory but I can’t find the right path to it. This piece of code doesn’t work:
update_post_meta( $pas_tasks_page_id, '_wp_page_template', dirname( __FILE__ ) . '/task-list-template.php' );
It works only when I put manually the template file into wordpress theme and changing code to:
update_post_meta( $pas_tasks_page_id, '_wp_page_template', '/task-list-template.php' );
But as a plugin developer I would like to create new template inside my plugin directory not manually. How should I do that?
I recently did something just like this using the “template_include” filter. I did it like this:
I just used wordpress conditionals to check what what template was being requested and then created a “theme_files” folder in my plugin directory and placed the appropriately named wordpress template files in there. This was to create a single and archive template for a custom post type.