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?
- Create custom page templates with plugins?
- How to structure a plugin
- What Features would you Most Like to See Added to WordPress? [closed]
- is_plugin_active function doesn’t exist
- Proper Way to Modify Plugin
- How to edit a wordpress plugin without break its update process
- Looking for a Table of Contents (TOC) plugin for WordPress
- WordPress Plugin Development In MVC Architecture, How?
- How can I import a class privately into a plugin?
- Where should I use get_option in a plugin
- GPL and plugins
- Custom Taxonomy in plugin and template
- Disable Specific Widgets on Selected Pages of a WordPress Website?
- Create page when plugin is activated
- Integrating plugins in themes
- How to show custom message once on plugin activation?
- Post source link plugin – small modification
- How to add users roles dropdown in registration in wordpress
- wp_schedule_event / cron_schedules – custom recurrence time not working in Plugin
- How to load a new template page according to a particular URL?
- WordPress network: set themes and plugins for new blog
- How to edit plugin’s html? [closed]
- Can a plugin add to header/footer/body content?
- Creating a wordpress plugin where users can override templates
- Multiple plugins using the same OAuth class issues
- How do I future proof my older WordPress theme?
- Organising the plugins folder in wordpress
- force customers to add only single item to card per purchase EDD [closed]
- Preventing BFA in WordPress without using a plugin
- Output HTML only on individual post view
- Manually add order item with fixed product_id in WooCommerce
- ‘Customize’ button in admin bar for CSS
- Auto delete WordPress users according to time
- How to use get_theme_mod in gutenberg editor wordpress?
- How to show Recent Page instead of Post?
- Creating plugin using simple_html_dom parser?
- How would I go about creating a user ranked post popularity page?
- 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]
- Overide plugin files from child theme (/inc/ ) folder
- How to display (plugin?) output on a single page (not a widget, probably not a short code) – template, plugin, combination?
- Advanced Custom Field DatePicker [closed]
- Calling an attribute from a plugin shortcode
- Why can’t I access my Intranet LDAPS with NADI?
- Include comments form in plugin page
- Setup page on first login on multisite
- Redirect to another page using contact form 7? [closed]
- Login Customizer doesn’t change the background of the register form
- Integrating WP E-commerce plugin into custom theme
- Custom post types – remove default post supports through empty array?
- When I try to de-activate any plugin it gives error “Warning: call_user_func_array() [function.call-user-func-array]”
- Use $variable from file1.php in file2.php (different file paths)
- Plugin Admin Menu Boiler Plate
- WordPress – source link plugin – how to modify it?
- How to create plugin in wordpress [closed]
- I want to filter my products with attributes [closed]
- Action on WordPress Install
- reCAPTCHA on page template without plugin
- Trying to include files in plugin isn’t working
- Delete data from custom table when deleting a post
- Pull comments from one page/post into another page/post?
- What is the best way to make a custom page from a plugin?
- Automatic recurring payment using YITH subscription and Dokan Stripe
- How to customize maintenance mode notification in wordpress?
- Displaying page content from plugin, inside exising empty WP page
- How to keep plugin (media-sync) running even the tab is closed?
- Hide fields in woocommerce settings
- implement custom roles in custom plugin
- Adding LOAD MORE on a page
- How to check if short code is present in template?
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Cron job shedules replace?
- Widget display in theme
- How to use custom footer template in a site-plugin?
- How to write wordpress plugins faster to load?
- Customize a widget position
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- Convert HTML5/CSS3 site to WordPress Theme (need a lot of plugins) or just use the API?
- wp_query for more fields plugin
- Including a PHP file via a function that is part of a plugin?
- Pronamic Info Window
- Shortcode return is printing a 1 afterward
- From a legal perspective, is it okay to customize a plugin’s code?
- Child Plugin Admin Panel
- Does anyone have the Custom Post Permalinks plugin from John P. Bloch? [closed]
- Create Custom Coupon Type
- Using ACF to allow user to add and edit multiple saved forms
- How to provide page_template path in custom plugin using WordPress