According to the WordPress Codex, using template_redirect
to load a different template is discouraged and can cause certain code to not be executed, which of course can result in strange bugs.
template_include
is the more appropriate solution. It loads a template file but without the behavior mentioned above.
add_action( 'template_include', function($original_template)
{
if (is_singular('business'))
{
load_template(get_plugin_path() . 'templates/business.php');
}
return $original_template;
});
Related Posts:
- Looking for WordPress System Diagrams
- How can I load a page template from a plugin?
- Overwrite theme file from plugin
- How to control output of custom post type without modifying theme?
- When is it appropriate to put functions on page template vs. functions.php?
- Filter to change the content of 404 page
- How to properly use a hook to create template for custom product type in a plugin such as Woocommerce? [closed]
- How to check active theme is parent or child wordpress
- WordPress removing data attributes for scheduled post
- Is there a way to loop through a shortcode datasource to create a table?
- creating custom archive template within plugin for custom post type using archive_template filter
- Where to call wp_enqueue_script in a plugin with custom template?
- Can Page Templates be Applied to Archive and Post Templates?
- ORDER BY wp_post custom column name in wp_query
- Create a free scripts and styles template within a plugin
- How can I turn a custom wordpress page into a product page?
- Plugin templates vs Parent Theme
- How to make “upgrade safe” theme for a plugin?
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- How to create templates for a custom module to show on the front end within my theme?
- Plugin custom post template; without overriding all posts
- Best way to distribute templates and code accross multiple wordpress sites?
- Load php file with jquery in single.php
- Overriding the template files using a plugin for all themes
- How do I use a plugin to swap out the template file for a custom post type?
- Javascript not being loaded only in custom taxonomy template
- Add new header/footer on landing page with plugin
- Use a page as a template for a custom post type
- Page template compatibility with different themes
- How to set custom homepage via a plugin
- Template file structure , wordpress hook for altering the template
- Displaying External Data – Not Posts
- Making plugin output customizable
- Use different archive template for plugin
- How to display custom taxonomy and terms using/creating plugin template
- How to check during “pre_get_posts” if WP performing default query for specific custom template?
- WP Job Manager – Show recent jobs as cards
- Help interpreting @wordpress/create-block-tutorial-template usage error
- Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
- How can I add an image upload field directly to a custom write panel?
- Creating a table in the admin-style?
- On the WordPress Admin section how do I link to submenu pages created for a plugin?
- How to return only certain fields using get_posts()
- Scheduled events disappear from events queue
- Where is it better to start learning how to develop for WordPress?
- How to log plugin errors to plugin error_log file
- Is there any way to test if a function running only on plugin update is successfully running?
- Using wp_cron with custom time interval and the register activation hook
- Throw 403 in a plugin [duplicate]
- WordPress multisite apply different options over each site from same plugin
- Using ob_start() in plugin
- Hook for post permalink update
- How can I view all WP generated thumbnails in Media Manager?
- Only allow plugin to be activated on root site of multisite
- Load page template with custom content using a plugin
- How to put placeholder text in the main post input area?
- how to redirect to another post without getting headers already sent error?
- Redirect user to a particular link in 10 seconds after using wp_die
- Getting admin notices working for plugin errors
- Change template dynamically
- add a class when login
- An echo line in a transition_post_status action leads to “cannot modify header information – headers already sent by”
- Programmatically detect if wp-cron is disabled?
- Widget is to be compatible with all themes
- How to create a table with filters for my plugin
- Passing nonce at admin menu link
- wp_insert_user() function password never match
- Preview plugin store details
- Prevent third party plugin’s admin page access based on user type
- Get attachments from a post
- I have 2 plugins using the same wp_login action hook and one is not working
- TEMPLATEPATH without the theme name? No THEMEPATH constant?
- wp_update_post deletes post meta in CPT
- Update Data parameter of a wp_localize_script() call
- flush rewrite rules after plugin update?
- Download button in a plugin’s settings page
- Data not insert and update through ajax and jQuery in admin page?
- Adding custom stylesheet into header.php using a plugin
- Developing the save function in Gutenberg blocks
- Creating an installation zip file
- update_callback is not working in register_rest_field
- Detect change in site_url and home_url
- Reporting errors in a shortcode plugin
- Why is the form not updating when I select a new sector from the list?
- How do I add a menu item to a Pods admin menu?
- Is there a way to add a link with add_post_meta?
- How to Show Category List With Corresponding Links?
- .htaccess with WordPress – create my own pretty url with parameters (above WordPress settings)
- How do I add a 5 digit ZIP code validation to a Contact7 form?
- How can we stop showing short code in create or edit post section
- Delete Plugin Options with Verify
- set a custom post type to a taxonomy term programmatically in metabox
- How to create custom frontend php page via plugin
- How can I add recent posts to menu like mashable
- Translation of plugin Upload button
- Changing upload directory for plugin uploads only
- How do I query posts and have their related taxonomies returned in the results?
- add_filter adds output in the head
- Update option hook not firing
- $_GET vs get_query_var()