I’m creating a plugin for a custom post type. I want to add a custom template for it. But I’m not sure how to add it via the plugin.
How can I add a custom post type template via the plugin?
Please help!
I’m creating a plugin for a custom post type. I want to add a custom template for it. But I’m not sure how to add it via the plugin.
How can I add a custom post type template via the plugin?
Please help!
You must be logged in to post a comment.
You can simply create and assign custom page templates for your custom post type in your custom plugin.
Just create 2 template file – single-{post_type}.php and archive-{post_type}.php – in a new templates sub-directory of your plugin directory.
Then add some code as per below example in your main plugin:
Hope this example would be helpful for you.
Cheers !!
Below is a complete (blank) plugin that I put together based on my previously posted answer. I loaded it in my theme (based on twentyfifteen) and it works. Together with the plugin, as-is, you would also need The following file structure
It should not be too tricky to figure out what should be in the above files, but for starters just put “
<h1>{filename}</h1>
” to see where each page is called.I hope this helps a bit more.
This work for me, kindly try it, Thanks
Templates is loaded into cpt file, which was located at
custom_plugin -> app -> cpt -> cpt_article.php
Template is located
custom_plugin -> app -> templates