You would need to add a filter to the page_template
hook that will look for whatever criteria you need.
For example, if your plugin was for a custom post type you would have something like this:
function myCustomTemplate( $page_template ) {
// Check theme for template file
$located = locate_template( 'single-{{postype}}' );
if ( ! empty( $located ) && is_singular( '{{posttype}}' ) ) {
$page_template = dirname( __FILE__ ) . 'templates/my-custom-template.php';
}
return $page_template;
}
add_filter( 'page_template', 'myCustomTemplate' );
The $located
check looks to see if the user’s current theme already has a file to display the custom post type already since you probably do not want to override that. If it doesn’t and the post type is the custom post type your plugin defines, then it will tell WordPress to use the one with your plugin.
Related Posts:
- show Visual form builder in the front end
- Consuming an external API in WordPress?
- I need to add a custom “cover” to every new post — plugin or custom setup?
- changing posts layout in ultimate member profile plugin
- Best practice for including plugin output in a template without using shortcode?
- WordPress as template engine
- Multiple Post Thumbnails Plugin – Need help with code
- WordPress hierarchy clarification, does post_type_archive take precedence over taxonomy-term archive?
- Customize plugin templates
- WP plugin calls for custom pages
- [Custom field template plugin] Upload limited to 20 inputs file
- How to display content depending on the Woocommerce Product Category
- How to make a Template page to show the information of different things Shop and Product page?
- 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]
- Creating plugin using simple_html_dom parser?
- Translating long texts with html formatting
- How would I go about creating a user ranked post popularity page?
- List Category Posts rewrite necessitates rewrite of customised templates
- 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
- Disable woocommerce cookies and delete cart data automatically
- WordPress comments not appearing in blog posts, likely because of Redux template. Could I fix this with a plugin that adds a comment form as a block? [closed]
- className not populating in custom block
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Run plugins only on certain pages
- (FES EDD) New vendor submission page is blank
- Plugin-generated pages use Not Found or Pages Archive templates?
- Overide plugin files from child theme (/inc/ ) folder
- wp_generate_attachment_metadata is creating an empty array
- custom payment gateway in woocommerce failed to connect to remote api server
- Display encrypted content on my website
- How to display (plugin?) output on a single page (not a widget, probably not a short code) – template, plugin, combination?
- Post category with counts been display like a menu
- Post custom Data value in The Events Calendar plugin [closed]
- Send reply with pre-prepared answers
- Facebook Messager Plugin
- Best way to maintain and update 3rd-party WP plugin when developer is unresponsive?
- Save custom attributes of product in woocommerce
- Advanced Custom Field DatePicker [closed]
- Calling an attribute from a plugin shortcode
- Best place for short bio,image and button [closed]
- Add comments for template variables
- Why can’t I access my Intranet LDAPS with NADI?
- External Domain on WordPress Multisite
- In the archive widget, how do I sort in between two years?
- Customization API for plugin development
- Fromcraft Plugin On click submit button [closed]
- Include comments form in plugin page
- creating a custom shop page display on archive woocommerce
- Setup page on first login on multisite
- polylang + category/tag custom language link
- Anspress Customization: How to show logged in user votes on a single answer?
- Custom wordpress Theme and Plugin repository
- Automatic Updates Individual Plugins Not Working
- How do I make a child theme I made POST through a 3rd party plugin?
- WP Plugins – Use includes to display page content
- How create Group Blogs based on user created Groups
- Render custom php template into string
- Perform internal redirect in WordPress?
- How WordPress is able to change locale without using setlocale
- How to redirect users to their profile after they successfully edit their profile
- Custom table naming/access convention for multisite: $table_prefix vs base_prefix or other?
- Add ALT attribute to Pin It Button image to pass HTML5 validation
- date/time-picker and file upload (image) fields for custom fields (e.g. with more fields)
- Getting Theme element into plugins page editor in wp admin
- WordPress as web application base
- Customize The Events Calendar to Include an Option to Expand for More Events Listings
- URL rewrite of independent plugin?
- Plugin for users to create their own ads like Google Adsence
- GeoMashup plugin: how to customize cluster markers / icons? [closed]
- How do I apply style to each category of a list?
- Add category selection to custom post type (plugin)
- Is there any hook for theme activation ? or something similar?
- How to use get_template part in the plugin?
- Redirect to another page using contact form 7? [closed]
- Template filter for custom taxonomy terms
- “No Add Button” for me to customize my WordPress with themes and pluggins
- Translation plugin to translate another plugins
- how to force tag page layout to use same as search layout?
- Login Customizer doesn’t change the background of the register form
- Inserting custom PHP script on homepage
- Creating Featured Content Boxes
- How can I use a file in my plugin as a replacement for single.php on custom-post-type query?
- Integrating WP E-commerce plugin into custom theme
- Calling the_excerpt from inside a plugin template file
- Custom post types – remove default post supports through empty array?
- Basic gallery plugin suggestion [closed]
- Timber – Twig post.content returns null can’t create ACF Gutenberg blocks
- a weird attribute on every html tag
- How can I run a custom shortcode function on a live site and only run if the viewer is a specific machine?
- Where to find the code used to render a page that has a shortcode and a template defined?
- Contact Form 7 – Form name blank [closed]
- How do i get file_get_contents to work in wordpress
- Custom widget doesn’t save values from dropdown box
- Plugin Development – Functions or Hooks?
- How do I override plugin templates and stylesheets?