While writing advanced plugins using custom post types sometimes it becomes necessary to completely take over the display of the particular custom post type display template. While using filters can work for most things sometimes a whole template must be included. One example of this would be if using the custom post type as an endpoint for an api request, where having any additional markup would cause the request to fail.
To include the template from the plugin directory the template_include filter has to be used. The code below will check in the current theme directory before including the one in the plugin folder. This allows for the theme to always be able to override the template. This also shows how to include multiple templates, using simple conditional statements like is_single.

By Stelios March 5, 2013 - 6:09 am
Hi Jeremy,
This is great…thank you very much for sharing, is it possible to show us also how to do this with header and footer so that we can override header.php and footer.php with custom files from our plugin folder?
It would be amazing and much appreciated.
Cheers,
Stelios
By Jeremy Clark March 7, 2013 - 1:12 am
With this method above your overriding the whole template so in the template itself you could put your call to the header and footer from your plugin folder. I’m not aware of a way to override just these template parts. There is no filter that I can find in the get_header function that would allow someone to override it if necessary.
By Stelios March 12, 2013 - 2:46 pm
How can i call header and footer from my plugin folder? Can you show this? I really need this because now the plugin loads the custom template which is awesome but it is still loading the header and the footer from the theme.
By Jeremy Clark March 12, 2013 - 2:50 pm
In your template in the plugin folder simply replace the get_header with
and get_footer with
By Stelios March 12, 2013 - 4:44 pm
Just by adding the lines below will override default/theme ones?
inlcude( PLUGIN_PATH . ‘/templates/header.php’ );
inlcude( PLUGIN_PATH . ‘/templates/header.php’ );
Can i place those at the beginning of plugin file or should i put the one for the footer at the bottom?
Thanks
By Jeremy Clark March 12, 2013 - 4:45 pm
You need to add the respective header.php and footer.php calls where the header and footer would go. So header at the top of the template and footer at the bottom.
By Stelios March 12, 2013 - 4:49 pm
Oh now i get it….you said template file….i thought that i would have to add those in plugin.
Cheers,
You are awesome
By Stelios March 12, 2013 - 4:46 pm
Sorry i meant
inlcude( PLUGIN_PATH . ‘/templates/footer.php’ );
(second line of code)