locate_template()
only look for a specific template in themes, not in plugins, so your function wil never work. This also goes for get_template_part()
which is in essence just a wrapper function for locate_template()
.
You will need to use funtions like file_exists()
to check whether or not the required template exists and then use something like include()
to load your template. You can use the above to write your own function like locate_template()
, this is at least what I will do, and have a fallback to lacate a template in themes should the template not exist in the plugin.
Just a note, always always first check if a value/template/condition exists before doing something with it. This will avoid unnecessary bugs and issues should a failure occur. Also, have something in place like returning false, adding a redirect, exiting etc etc to safely handle your code should you have a failure
Related Posts:
- How to implement WordPress plugin update that modifies the database?
- wp.media update options and force render on uploader
- WordPress Plugin Development In MVC Architecture, How?
- Customize plugin update “new version is available” text
- category_name not working (not showing up in sql query debug)
- “Donate to this plugin” for WordPress.org Plugin Authors
- What happens when two plugins have the same 3rd party class included into them?
- add_rewrite_rule, plugin activation and plugin deactivation
- How to handel multiple checkbox field in the admin settings page with Settings API
- Update Multiple Post Meta for the Same Post In One call?
- Allowing Custom Capability to Manage Plugin Options
- wp_insert_user – how to send verification email before logging in
- Custom plugin settings: clicking “save changes” does not display success message
- How to show custom message once on plugin activation?
- How do I configure WordPress to talk to a Microsoft SQL Server database?
- How to load a new template page according to a particular URL?
- How ( and mostly at what time ) can i prevent the alternate cron from running?
- What is the function to get plugin base url in multisite?
- PDF download – use wordpress functions
- How can I filter blog name?
- API to filter new user registration $POST data?
- Detect if a plugin was included in a certain page
- Set cookie then immediantly refresh the page
- How to add an attribute to the body tag with a plugin?
- Override the core function locate_template
- Admin page: form with enctype=”multipart/form-data” does not transfer its data
- Set user ID at time of wp_create_user
- How to Create a Custom Plugin Permalink
- How to create custom tables in WordPress using my own plugin?
- How would I go about creating a user ranked post popularity page?
- link bbpress forum discussion to blogposts
- How to modify WCMP Rest API response?
- Making a Template for a CPT created by a plugin
- Woocommerce dependent plugin
- External CSS in WordPress Plugin [closed]
- get 404 when accessing wp-admin/plugin-install.php
- Woocommerce Minimum Price for a Composite Product to add in cart
- Re use the list table for a custom post type on another page
- Can we have an ‘Update metadata’ button in Image Gallery for all image instances?
- Customised plugin failed to install and activate
- Why is one phpunit test throwing an error on one class when all other classes are similar without error?
- How To Extend A WordPress Plugin Without Losing Your Changes [duplicate]
- WPDB: Update table
- How to get all posts belongs to a user between a certain date
- Check filter defined or not?
- wp-load.php redeclares classes
- Plugin main file is constantly been fired on every website visit
- Where should custom post types be registered in a plugin?
- License validate function
- wp_enqueue_style on template_redirect level?
- Change the number of plugins counted on wp-admin/plugins.php
- plugin uninstall function drop the tables, but shows errors on admin
- How to use template inside plugin shortcode with variables for big HTML code
- Way to send multiple values for column to MySQL?
- Symlink a plugin in local development, works but got Debug error message – Windows 10
- why the wp_register_script doesn’t work for register_activation_hook
- Plugin is creating posts twice
- How do I reliably find a URL to a script or other file?
- How to add captcha to publish widget
- How to add logo to a WordPress Custom Plugin?
- Use a custom block in another block
- Set Button in PluginDocumentSettingPanel Content (WordPress Gutenberg)
- GitHub plugins safe to use in my website?
- Fixed: Console.log twice in the edit function
- Using OR Condition with facetwp facets
- How to copy the all WordPress media items to another custom plugin folder?
- Personality quiz in wordpress using a plugin
- How can we get this dynamically as this folder may not be by the same name always → wp-admin
- Error on plugin activation and creating new page
- Child theme modifications not showing up
- Why is my shortcode not working?
- Link custom post type to page
- implement checkbox or toggle switch in plugin code
- wp_remote_post To external API multiple values with the same key
- wordpress form not saving or updating
- Function settings_fields() not recognized (Uncaught Error: Call to undefined function settings_fields())
- what’s different between wpdb->prefix and table_prefix
- Can we rename a plugin directory for a already launched plugin?
- How to use custom footer template in a site-plugin?
- How can I call functions from a custom plugin?
- How to get short description under heading – Visual Composer [closed]
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- How to create a new database table whenever user changes options
- Am I correctly adding styles to plugin?
- How can I insert a record into a custom table from my custom form in my custom admin page?
- how to create table during plugin installation in side a class
- WP_Filesystem usage within a block of code
- Proper Failure of Plugin Activation
- Why function hooked using object are executing at all time?
- What is the Object for WP_Error Class?
- How can I use multi Media Uploader in a plugin?
- Ajax in Plugins: returns the whole page
- Gutenberg: Dynamic Block – Show saved data in the editor
- how to search through plugin in wordpress cimy-user-extra-fields?
- Any way to hook into WP after a page displays?
- wp_handle_upload – specified file failed upload test
- how to make wordpress remember my choice
- Running a function using Crown WordPress on one day a week, for example, Mondays of every week
- How to make a Template page to show the information of different things Shop and Product page?
- wordpress admin-ajax bad request 400