You need to use the template_include
filter which is the generic filter for all template inclusions.
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;
}
I’ve not fully tested the post type archive bit, you may need to include a check using is_tax( $taxonomies )
to get it to work on associated custom taxonomy archives.
Related Posts:
- Template for custom post type shows all posts instead of just one
- Ways to have multiple front-page.php templates that can be swapped out?
- Creating a default Custom Post Template that a Theme can override
- Get image URL from media library in input
- how do i remove posts from a WP_Query so the pagination is right?
- How can I use a file in my plugin as a replacement for single.php on custom-post-type query?
- Calling the_excerpt from inside a plugin template file
- Where to find the code used to render a page that has a shortcode and a template defined?
- Price comparison table based on Custom Post Type?
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- Accessing download link from the loop with WP Download Manager Pro
- Displaying image from a repeatable group
- Fake Single WordPress Post (Page) Loop
- WordPress show different custom post type
- How to display content depending on the Woocommerce Product Category
- How to provide page_template path in custom plugin using WordPress
- Include theme header and footer in custom plugin
- Load a custom post type template.html from a plugin
- Custom setup of wordpress comments that are displayed
- publish_post action doesn’t work
- Disable Individual Plugins (specifically in Custom Post Types) on a per-post basis?
- Recent posts per category loop?
- Best practice for including plugin output in a template without using shortcode?
- WordPress custom taxonomy not showing
- Timber – Twig post.content returns null can’t create ACF Gutenberg blocks
- Using ACF default value to autoincrement a number field
- custom post type don’t appear in the home page
- Import Instagram post to WordPress blog post
- Main query not querying any posts in custom taxonomy template
- Bulk update wordpress posts
- How to get a list of bundled products using wp_query in woocommerce
- How do I override plugin templates and stylesheets?
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- WordPress as template engine
- Default taxonomy template in plugin, override in theme
- How to Resize the Custom Post Images?
- Amazon.com intergration with WordPress?
- How to set category correctly for a custom post created by a remote API call?
- Sticky option for custom post types without using custom fields or plugins
- How to use template_include hook with form submission?
- Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme
- Adding custom meta boxes to specified custom post type
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- Plugin Admin Menu Boiler Plate
- posts from multiple post types in one slider
- How do we update a custom file upload field with the Advanced Custom Field plugin?
- Custom Post Type – custom form in dashboard
- Loop in elementor custom widget not working
- get_users(); Is an Undefined Function When Used in Cron Job
- Opening a JQuery modal window on click of a button with a JQuery plugin
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- How to use template inside plugin shortcode with variables for big HTML code
- Trying to add_action in a loop
- assign different templates to custom post type with homepage loop
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Assign a template to a custom post type when displayed by the main loop on the home page
- Get post content from outside the loop with plugin shortcode usability
- Pagination shows Same posts
- Custom form not showing in correct place on page
- Should meta boxes for specific pages be save in their own plugins?
- Call a function for social sharing
- WP-API Custom Post Type json_no_route
- How can I list custom post type categories of portfolio
- Preview with Custom Post Type Not Working
- How can I store data from custom fields to custom tables?
- 2 wordpress site same database
- Plugin generated unexpected output – No PHP errors
- How to Include Custom Post Content From Plugin
- Custom Template for wordpress cpt plugin
- “Allowed memory size” problem [closed]
- Custom post type change excerpt more and excerpt length
- Ajax Call in page theme not working?
- Remember the Meta Value With Radio Buttons
- Use jQuery Datepicker code from plugin
- What hook can I use to modify custom post data before it is displayed on the page?
- reCAPTCHA on page template without plugin
- How do I show content from a plugin using the template the site is currently working with?
- Woocommerce – Change Variable Product Add to Cart to behave like external product using Custom Field (link) [closed]
- Prevent plug-in scripts on a specific template?
- Output after specific post in the loop
- Create a custom taxonomy template that loops through child categories in term order?
- Order posts of a custom post type by the event date using FT Calendar Plugin
- Plugin is creating posts twice
- Polldaddy doesn’t show up on own theme
- Posts 2 Posts: Display custom types connected to the same other custom type but with another connection
- Creating teams of users in WordPress
- “After file loaded” action
- Custom Post Type template for homepage
- Pull comments from one page/post into another page/post?
- Add custom PHP and HTML to the_content()
- Multiple images per post – Show random image elsewhere
- hardcoded wp pages/plugins problems
- How to modify the Loop from a plugin (instead of a theme)
- Including content from legacy app: via plugin or custom content?
- How display specific category post to specific users?
- Dictionary-style definition list plugin
- Multiple Post Thumbnails Plugin – Need help with code
- Show Homepage (only) Hits Count
- Wp-minify doesn’t seem to minify my JS code
- Custom Post Type, Custom Columns List