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
- Pass PHP variable to javascript
- Is it possible to stop selected plugins from loading on certain template pages?
- Output before and after the loop
- How to make a list of companies’ information and display them to user, using custom post types and a custom taxonomy?
- Template plugin for blog posts? [closed]
- remove custom taxonomy metabox form custom post type
- [Plugin: Posts 2 Posts] reciprocal connections
- How do I make a wordpress plugin with menu item etc
- post expire after x days
- Way to hook into a sidebar call to replace it with a custom sidebar
- taxonomy_template filter do not loads custom taxonomy template properly
- wordpress reusable content blocks
- More than one text-domain is being used because of the included templates for plugins
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- Accessing post’s meta data based on user’s click of a post
- WP Post Template – Templates in own folder
- Is it possible to create Custom Post plug-in?
- List taxonomy terms for post as checkboxes
- How to make a proper custom post type link
- Matching Chapters to a Custom posts [closed]
- Insert content of a post into another
- Add comments for template variables
- Problem with the Loop – want to limit the access to three free articles
- How to use get_template part in the plugin?
- WordPress Plugin manipulate have_posts()
- What is the best way for showing a grid of customer logos?
- Best practice for including plugin output in a template without using shortcode?
- Default taxonomy template in plugin, override in theme
- 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
- Custom Post Type – custom form in dashboard
- $pages = get_pages(‘child_of=’.$post->ID); Why arguments are concatenated?
- Pagination shows Same posts
- WP-API Custom Post Type json_no_route
- Plugin generated unexpected output – No PHP errors
- “Allowed memory size” problem [closed]
- Remember the Meta Value With Radio Buttons
- Create a custom taxonomy template that loops through child categories in term order?
- Polldaddy doesn’t show up on own theme
- How to modify the Loop from a plugin (instead of a theme)
- Including content from legacy app: via plugin or custom content?
- Dictionary-style definition list plugin
- Multiple Post Thumbnails Plugin – Need help with code
- Wp-minify doesn’t seem to minify my JS code
- Custom Post Type, Custom Columns List
- Error Metabox Warning: call_user_func() expects parameter 1 to be a valid callback
- On click some element i want to use some template
- Pass PHP variable to javascript
- need click to clipboard button on my site
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- Create category for each user
- Enqueue css to a third-party plugin template
- Adding category base to url in custom post giving 404?
- custom post type plugin error [closed]
- Problem with checked box on wp car manager plugin
- Merging new theme and plugins from development site to production
- How to add post title to custom php?
- Is it possible to customize a wordpress post from outside dashboard(Something like site.com/post-type/post/?e=post_id)?
- How to access Post Archive created by Elementor?
- Programmatically generate new pages for a site based on page template and content elements accessed via DB
- How to change the deafult template in WordPress plugin
- WordPress arrows dissapeared strange signs
- Custom taxonomy template for custom fields loop [closed]
- Place content inside the Post Loop
- Calling an custom field from theme option at the frontend
- Creating themes using the one Plugin (Toolkit)
- How to add jquery to my custom post type wp plugin
- WordPress list child pages of custom post type
- Load different template for CPT (in loop) in my plugin?
- show Visual form builder in the front end
- WordPress Custom post type won’t save properly
- How do i use postMash to order posts in a custom loop?
- Getting Post Permalink Outside of Loop Not Working
- Remove base from the custom post type URL [duplicate]
- Trying to display posts but getting the pages as output
- Make a Custom template for a specific category in wordpress
- How to export post tags from wordpress
- How to make a Template page to show the information of different things Shop and Product page?
- How to access the page without registering in wordpress
- CPT template is not being automatically used single post pages
- Set the title of a custom post automatically by using info from custom fields?
- public custom posts not showing in my wordpress plugin
- plugin translation *.mo file not getting loaded for custom post
- Create CPT on Ajax Call
- Cannot register a block in my Twig-based theme using Timber for WP