You can use templates located within your plugin instead of theme files, like so:
add_filter('archive_template', 'redirect_to_plugin_archive_template');
function redirect_to_plugin_archive_template($template) {
if(is_post_type_archive('my_cpt')) {
return dirname(__FILE__) . '/templates/my_archive_template.php';
}
}
add_filter('single_template', 'redirect_to_plugin_single_template');
function redirect_to_plugin_single_template($template) {
if(is_singular('my_cpt')) {
return dirname(__FILE__) . '/templates/my_single_template.php';
}
}
Obviously you need to change the custom post type slug and the template paths, but that’s the general idea.
Related Posts:
- Custom comment type maybe?
- How to load a new template page according to a particular URL?
- Updating post meta for custom post types
- Themes VS Plugins [duplicate]
- I need to add a custom “cover” to every new post — plugin or custom setup?
- Is it possible to use WordPress as an online portfolio for text content? What kind of theme would I look for?
- Redirect to another page using contact form 7? [closed]
- How display specific category post to specific users?
- Custom Post Type, Custom Columns List
- Check if theme supports sidebar
- Adding category base to url in custom post giving 404?
- Adding LOAD MORE on a page
- Ultimate Members Default Post Layout problem
- Cannot view Custom Post Type no matter what I try
- Creating custom “player-objects”
- Will Flutter work with WordPress 3.0?
- Leveraging WordPress Comments on Custom Plugin Object page
- Copyright messages for a particular set of pages
- Custom Post Type | Fatal Error on register_post_type()
- Debugging Technique Question re: functions.php
- Check if User exists in WordPress Multisite
- wordpress reusable content blocks
- Override plugin with functions.php
- Is there a way to alter the order in which the plugins appear in the page?
- Getting Post details when post is published
- Override the filter from plugin in child theme
- force customers to add only single item to card per purchase EDD [closed]
- Preventing BFA in WordPress without using a plugin
- Custom plugins/Manipulated plugins: Always a terrible idea to inherit these types of WP sites that discourage updates? [closed]
- Delete Associated Media Upon Page / Post Deletion
- How to check what plugins used to be on a WordPress installation?
- Should i delete the posts created by a plugin on uninstall?
- wordpress.org codebase
- Output HTML only on individual post view
- Possible to replicate economist.com’s debate section in wordpress? [closed]
- Can a plugin deactivate and delete itself once installed and activated?
- Allow users mark posts as “complete”?
- Manually add order item with fixed product_id in WooCommerce
- FacetWP group listings by custom field [closed]
- How to modify shortcode attributes with data from current post
- ‘Customize’ button in admin bar for CSS
- Auto delete WordPress users according to time
- Is there a way to order posts and custom post types as one group?
- Plugin Customization Lost During Plugin Upgates
- RW Meta Box ,Problem setting post title
- How does WP handle multiple matching rewrite rules?
- how do i remove posts from a WP_Query so the pagination is right?
- Saving Custom Post types and fields to a custom table
- dynamically generating plugin syntax
- How to import my YouTube channel into WordPress?
- Building a store locator with google maps
- Custom Field Template seriously messed up in WP 3.1.1
- My Category is too big on the Menu what can i do?
- how to load the language file in plugin?
- Plugin upgrade issue
- Duplicate posts when posting nulls in records in phpMyAdmin [closed]
- How to use get_theme_mod in gutenberg editor wordpress?
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
- How to embed HTML code from WP Coder plugin (or other) into Main Index Template of the theme
- 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
- WordPress plugin – Error “Plugin generate 2890 characters of unexpected output when activated”
- How can I capture Memberpress user info after signup [closed]
- My plugin wants to update another plugin
- I have no idea “How change font for elements in widget?”
- View Private Published Page with URL Code (no login required)
- JS Support Ticket – Auto create WP account
- How to show Recent Page instead of Post?
- Remove Duplicator plugin from admin menu if not an administrator
- How to create user groups and allow custom posts and plugin modify/access to specific group?
- Input with spaces in Shortcode attributes overwritten by defaults
- Correct way to make meta box with more than one meta field secure
- I want to extend the current themes’ single.php to display the meta fields of my CPT
- Plugin custom post type – Internal server Error
- Exclude post by custom meta with pre_get_posts
- How can I create a custom shortcode that will return a custom post type by ID?
- Add a custom form on the post-new.php admin page
- Removing customise fields during plugin uninstallation
- Is it possible to create Custom Post plug-in?
- Edit Yoast SEO breadcrumbs output [closed]
- What’s the best way to implement AJAX in WordPress?
- How to Create a Custom Panel and Fields in Post Page [Plugin]
- get_post_type() and WP_QUERY issue
- Translating long texts with html formatting
- get_post_type on post.php
- List taxonomy terms for post as checkboxes
- How would I go about creating a user ranked post popularity page?
- All of my custom posttypes are 404’ing
- more types plugin – display all post of post type on page
- When using Simple Fields plugin, how do I pull the information out of the database to display on a page?
- Anonymous Postings
- Do widget options need to be escaped widget()?
- Is there any W3C compatible Share & Follow plugin?
- Does any one have Idea to get these functionalities with the plugin wp-multi-network
- How to make a proper custom post type link
- Matching Chapters to a Custom posts [closed]
- Disable woocommerce cookies and delete cart data automatically
- Custom post type – no layout section of Document tab, and no author choice
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type