Try…
function maybe_auth_redirect() {
if ( is_page_template('my-template.php') && ! is_user_logged_in() ) {
auth_redirect();
}
}
add_action('template_redirect', 'maybe_auth_redirect');
Related Posts:
- Is it possible to override the result of get_template_part()?
- Child Theme: how to override variables?
- roots child theme can’t override header.php
- Load template inside a parent template
- Child theme TEMPLATEPATH issue
- Updating modified templates
- Child theme template file will not load
- Checking for page templates in child theme
- Should template files be copied to the child theme for editing?
- Why does the Full-width Template in Twenty Twelve pack so many classes into the body class attribute?
- How to preserve changes in templates and other files
- Use same page template for parent and child pages in a theme
- Override Dokan Includes File in Child Theme
- lost css when overriding themes templates
- ACF costum date format [closed]
- What template is used for viewing Media Library Files?
- Page header on specific page is different from the rest [closed]
- Parent/Child themes – both CSS files loaded
- Child theme enqueueing style.min.css not style.css
- How can I make custom page templates work on child theme?
- Why would adding a template file to a child theme cause an error in template-loader.php?
- How to show children pages as array
- How can I add some blocks to template without changing template file?
- custom template – override plugin template in child theme – issue with scripts
- WordPress Template works until page becomes a child
- Unload templates; disable parent Template Parts using only “theme.json”
- How can i change email template for new user
- Enable page templates. How?
- Prevent comments_template() to load comments.php
- Page editor missing Templates drop down
- Custom templates folder
- How to Rename a Template File?
- get page templates
- How to assign a class to a page with a custom template?
- Proper Javascript Implementation
- Guest author’s post not display in author template
- How to apply a custom template for posts by default?
- Make “sidebar template” the default template for new pages
- Is there a way to check which template file is being loaded, if it is not a page template file?
- Add theme templates for child categories into the template hierarchy
- How to remove wp_link_pages() from template
- How can I get WP to use templates in lower-level subfolder?
- how to make a home page for wordpress custom theme
- Load child template based on parent
- Generate Catalog Of Posts Based On Template
- Extending body classes in front- and backend
- How do I find the directory of a page template?
- Is there a way to set different post templates for parent posts and child posts in the same post type?
- Why write markup for index.php?
- Having trouble with Template hierarchy. I Need to create a set of pages that drill down from states to specific locations
- Child theme does not load all style
- How can I hardcode template selection?
- Changing layout programmatically
- How to identify which template WordPress’s default search-form retrieves in my theme
- How to use same page template if post status other than ‘publish’?
- Installing plugins and using complex folder structure with child theme in WordPress
- Different Template based on HTTP Referer
- How do I override the search template in a plugin?
- Is there any way to write custom HTML is some .php file and then call it wherever necessary?
- How to redirect my custom template page to content-none.php if no posts found?
- Get URL of current post but not the page number
- Is template name always same as directory name?
- Single Post Breadcrumb not linking back to Custom Post Type Index?
- Form post to WordPress page = wrong template
- get_month_link uses what wordpress template?
- Load custom script on a single template
- Archive template limiting to 4 entries?
- Author template help. How to check if field exists in the profile?
- Can you use block patterns in block templates or insert them programmatically?
- Why does the Woocommerce grouped template prints the unpublished products?
- WP redirect to custom login page if a user is not logged in
- Change default template in the block editor (Gutenberg)
- How do I create post template for different taxonomy
- Ip2location plugin in my template header?
- Import a header template from another theme
- Will placing custom templates in sub directory break any native WordPress functionality
- Archive-custome_post.php template not working
- Change “posts per page” depending on width
- How to slice down index.php from a template and import from another file?
- Can index.php take over for front-page.php in template hierarchy on second page?
- What filter or action hook to use in order to load some code before the template begins printing in BuddyPress? [closed]
- How do I get tags linking to proper pages (/tag/sample-tag -> pages with that tag)
- How to name custom search page PHP file?
- get_template_part for template in subdirectory not working
- Assign template to custom page type?
- Accidentally deleted code in header.php
- Custom post template
- Main content not displaying using custom page template
- plugin overwrites other plugin’s archive-.php file
- Creating custom URLs with template to fetch external JSON
- How can I display a list of pages and the template used by each?
- Show a custom template, no matter the page being viewed, if the user is not logged in
- printf, translation and the_author_posts_link()
- Tag Posts showing in wrong places
- front page won’t change templates
- Including 2 Negative Is_Template Conditionals in header.php [closed]
- Add custom card template to masonry layout using Essential Grid [closed]
- Where is the general html template file?
- templates page not showing on gutenberg editor
- How to load php templates from html page (block theme)