function get_custom_post_type_template($single_template) {
global $post;
if ($post->post_type == 'events') {
$single_template = dirname( __FILE__ ) . '/single-event.php';
}
return $single_template;
}
add_filter( 'single_template', 'get_custom_post_type_template' );
Or you could use:
add_filter( 'template_include', 'single_event_template', 99 );
function single_event_template( $template ) {
if ( is_singular('event') ) {
$new_template = locate_template( array( 'single-event.php' ) );
if ( '' != $new_template ) {
return $new_template ;
}
}
return $template;
}
Or you could use locate_template
Related Posts:
- Loading custom page template via plugin
- How to use a dedicated template for the Custom Post Type from a plugin?
- How do I create a custom post type for a training CMS in WordPress?
- Using custom page templates with plugin [duplicate]
- Dynamic assign a custom template to custom post type posts
- How can I load Template file from wordpress plugin
- I want to show a list of posts under specified categories
- I want to show a list of post with title that have link goes to that post and icon under the specific category to which it belongs
- How do I change the author of a custom post type?
- Add Content to Page without shortcodes
- How to add a button to custom post type’s posts-page
- Creating a custom public user page
- Is flush_rewrite_rules necessary when creating a custom post type? Why?
- Dynamic page.php template for custom post types
- Remove Slug from Custom Post Type results in 404
- WordPress metabox file upload in custom post [duplicate]
- working Custom Post Type and Widget code no longer works when moved from functions.php to plugin
- Multiple templates for custom post type
- Insert slider (Custom Post Type) into pages
- WP Query group/order by category name
- Save or update data when custom post published
- How do I create a page template to display a custom post type?
- How do I add a custom button to my “edit” list? ( edit.php?post_type= ) beside “Add New”
- How to add multiple featured image in meta box in post editor?
- How to add notification in the sidebar of the administration panel when a Custom post type is created? [duplicate]
- Custom Post Type get_post_type_archive_link( $post_type ) returns false
- How do I set the link in the Custom Post Type admin menu?
- How to List Thumbnails based on Custom Categories
- Adding Meta Boxes while Registering a Post Type in a Class
- How to have the right design for a custom post type without accessing themes
- Dynamic Custom Post Type Plugin
- After updating a page, all pages on the site used the index.php template
- Page Templates Drop Down Select for Custom Post Types
- Set object terms not working on plugin activation
- Get all of user’s custom post types in WP Admin for plugin
- Troubles with making a custom template for posts
- How to Get Current Custom Post Type Selected Taxonomy Term (Not All Terms)
- Custom Post Type: Upload Multiple Images
- Change archive page template using pre_get_post
- How to add a custom taxonomy to show up in a custom post type menu?
- Give a permalink to Custom Post Types without title
- Getting template_include to work when allow_url_include is off?
- WordPress showing archive.php instead page
- Custom Permalink to remove category word , keeping posts permalink with date?
- Form action/link to render a plugin in WordPress front-end
- How to Create a WordPress Plugin With Custom Post Type/Custom Field Features?
- Adding the_content() in custom template email
- Adding a metabox on a CPT’s submenu page
- ACF in wordpress
- Theme independent plugin by using default page template
- How to add and clear custom post types and taxonomies in a plugin? Considerations for existing data
- post_parent in custom post type
- Dynamically insert code to custom post type loop
- How do I add custom HTML to the content of an archive page’s posts?
- Unable to format dates to put in event calendar
- How to add query args to links to CPT admin submenu
- How to get the current category with custom posts
- How to add and display custom content that is not a post
- Custom post type in Custom widget – $listItem
- Problem with adding custom post type meta to header by plugin
- Creating alternate meta box context locations
- How to add page under a custom post type?
- Convert Custom Table Data Based Plugin To Be Searchable
- Custom Post Type Specific Post Template
- Using get_terms() to list terms from one custom taxonomy AND from one specific built-in category
- Limiting Amount of Posts in a Custom Post Type again
- Wp Meta Query does not work while simple Query Works
- How To Display Posts Of Custom Post Type At Page Template
- Auto update publish date of CPT Post if default post custom field value match to cpt post CF Value
- Why are custom taxonomies only appearing on the edit page of one of these types, but not the other?
- How to add a default predefined thumbnail when creating a brand new post?
- How can i display a taxonomy? i have created a plugin and then a custom type. and a taxonomy , also i have register it
- URL issue retrieving Custom Post Types using Backbone JS API
- WordPress Custom Post Loop
- Create a post automatically if search result has zero results
- Correct way adding External classes to Custom Post type and output their methods to template
- WordPress Page hierarchy ( parent is singular of custom post types slug ) is returning not found
- ‘Simple’ Reservation System
- Custom post type not pulling CSS
- Show Post columns to specific users on condition
- Custom Post type plugin is using theme single.php and style.css
- Run query on specific admin options page and send results to select field in another function
- Not able to get all the actions (View, Edit, Quick Edit, Trash), and not able to delete post in custom post type
- call a function when insert and update a custom post type
- Custom post type not being pulled in widget
- Registering an optional custom post type from a plugin
- Can not hook into custom post type template with: is_page() conditional?
- custom fields not showing before get_header
- Page Template For Custom Post Type doesn’t work on URL containing CPT name, other URL’s work
- Custom Post Type Pagination Not Working or Single Posts Displaying?
- Generate custom RSS from a plugin
- Query custom post type and showing its content
- Issue on Counting CPT’s Under Taxonomy Term
- Modifying and Displaying URL’s in a Post Template using parse_url
- Custom page template not recognized with permalinks on
- Inserting into WP DB
- Adding custom theme template to custom post type [duplicate]
- Can you programme the selected page template to display block patterns automatically?
- Create settings page to enable or disable CPT
- How to consume external API from WordPress post editor and display the response data in the custom field?