Can you perform the logic on the template_include filter? Else, you could set a global/constant and use that in template_include to serve up the appropriate template.
The template_include filter filers the path to the template file to be included. To avoid errors you should check if the template exists – locate_template does this for theme/child-theme files.
add_filter("template_include", "sc_redirect_properties_to_registration");
function sc_redirect_properties_to_registration( $template )
{
if( is_user_logged_in() && ! is_page("the-properties") )
return $template;
//You could include templates from plugins
//$template = plugin_dir_path(__FILE__).'templates/plugin-template.php';
//Best to check the template exists. With **theme/child-theme** templates
// you can do this with locate_template.
return locate_template('template-registration.php');
}
Related Posts:
- How to add attributes to tag when template cannot be directly modified
- Would like to use hook or filters to customize email templates
- WordPress hooks/filters insert before content or after title
- How do filters and hooks really work in PHP
- Trouble understanding apply_filters()
- How to pass/get data to/from the WooCommerce data-product_variations object?
- Filter hook before create order WooCommerce
- wp_mail – Remove sitename from email subject
- apply_filters() slices away needed arguments
- WP Rest API – Upload media without saving attachment post
- How to make post and comment count unclickable with dashboard_glance_items hook
- How to add attribute to output with wp_video_shortcode add_filter
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- How to limit the pages displayed for choosing parent page on page attribute’s menu?
- How can I reliably and globally disable wptexturize?
- Customise Jetpack Publicize text
- WordPress RSS feed – filter RSS content by custom field value
- filter the_title problem in nav
- How can I add a fifth option to the alignment picker?
- Filter the URL of next_posts_link & previous_posts_link
- How to replace any occurence of Gravatars with a local placeholder image?
- Sensei LMS Hooks to Remove Content
- What hook/filter can I use to add/edit/show/hide the title under (on hover) links on the table view?
- Customize user account activation message
- Conditionally call add_action depending on post_type?
- Change WordPress RSS link with filter?
- Add a header before fields added with the attachment_fields_to_edit() filter
- Error when overriding only some audio shortcode HTML output
- Hide content editor for posts after approriate date
- Gutenberg disable the “block” tab in right sidebar
- Why my admin doesn’t work after adding rest_prepare_post filter?
- When to use actions and when to use filters
- add_filter to ‘woocommerce_before_main_content’ [closed]
- Editing
- Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?
- Same Conditionals Not Working on Two Different Hooks
- How to call a function or method that is Namespaced using another plugin
- check to see if hook is available
- Change username before login
- How do I target a single page to modify the comment form of only that page?
- How to removes all instances of thumbnails displayed in my theme?
- theme_page_templates not working
- Insert term when page is published – avoid duplicates after edits
- When does a function assigned to the content_filtered_edit_pre filter hook fire?
- Capture post content before page renders
- Remove_action does not work
- Make an array filterable per hook
- How do I add a checkmark to my-sites save settings hook
- Comment search plugin
- How to know what filter to use and how to use it?
- How to filter backend post list showing only posts having a shortcode
- Add Lightbox To WordPress Native Gallery
- What hooks to hook onto for automatic cache clearing
- Modify Redux Framework Options in Child Theme
- Adding a filter to comments_template
- How to customize category_description()?
- Detect when gutenberg editor title is available in Dom after editor load
- How can I output all apply_filters and do_action?
- Set default value for “Additional CSS class(es)” for specific block types
- Disadvantage of using filters & hooks multiple times
- How do I hook my function to run only after submitting login form
- Change the template when the user is not logged in using page_template filter (it does not work)
- Admin post list – adding an option to the date filter dropdown
- How to add a filter to the get_body_class function?
- Prepending character(s) to a custom tag title?
- Modify existing plugin function with add_filter
- How to override include_once pointed file using add_filter?
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- comment_for() Custom fields not visible when user is logged in
- What is the action hook to use if you want to capture the new password during password change?
- Is this hook really deprecated? ( manage_{$taxonomy}_custom_column )
- an action hook when a post reaches a certain number of views
- Shortcode / plugin with custom (flexible) output
- Action hook to control access to certain parts of my site
- Need to return shortcode text instead of the output
- output custom Posts on a Page
- BuddyPress – A hook available to hide custom born date on public profile view?
- Replace Data In Post & Update Meta Field Post Is Saved
- The gettext hook doesnt work on text with links
- How to add custom media library mime icons?
- Add an attribute to the root from functions.php with add_filter
- Hook to add content after date in post?
- Is it possible to assign a css id to a row in plugins list table?
- Add Index to Item in WordPress Gallery
- Remove image of srcset
- Security question – Display a General Custom Login Error Message
- Add HTML to the bottom of each post in a post list
- Incrementing content with extra text after save/publish
- wp_editor customization
- Filter dashboard custom post listing by user
- WooCommerce comments_template Filter Not Firing
- if i put the code in my theme’s function.php file can it work?
- Admin New Order: Autofocus on Search a product
- NextGEN Gallery: Adding drop-down menu widget to gallery view without modifying plugin code [closed]
- How to filter part of a variable if it is no array?
- str_replace css meta tag?
- How do you disable the verification process of user email changes?
- Can you call a filter hook by “add_action”?
- How to Dynamically Switch WordPress Front Page Without Causing Canonical Redirect?
- How to add custom field to top of WordPress Comment Form for both logged in and anon users