The list of available templates is generated by get_page_templates
. By the end of this function you see a filter that allows you to modify the output. You can use that to change it under certain conditions like this:
add_filter ('theme_page_templates','wpse302574_conditional_templates', 10, 4);
function wpse302574_conditional_templates ($post_templates, $this, $post, $post_type) {
$parent_id = wp_get_post_parent_id ($post->ID);
if (get_page_template_slug ($parent_id) == 'slug_of_your_parent_template') {
// remove unwanted templates from $post_templates
}
return $post_templates;
}
( I didn’t test this code, some debugging may be necessary )
Related Posts:
- How to remove the Theme Customization Button from the dashboard and themes options page?
- Display a different theme for not logged-in users
- Get password when user registers and save it sha1 into database
- Passing variable in hooks and filter
- Highlight “Show all” item in wp_list_categories
- Menu item added in wp_nav_menu_items filter is never highlighted
- Injecting a custom sql query into a page/theme
- Pass variable to hook. Its possible?
- How to change footer credit text in Twenty Twenty One theme with a hook?
- WordPress wp_get_current_user returning blank values until refresh
- How to show children pages as array
- what is do_action(); in wordpress? [duplicate]
- Is there any filter or action hook to remove layout classes from appearing in my templates?
- How to move page template files like page-{slug}.php to a sub-directory?
- Add custom classes to anchor in wp_nav_menu
- What filters are applied to the_content function?
- Define custom Page Template without its own .php file
- Change admin bar to default:off
- How to modify an image block in Gutenberg WordPress 5?
- How to move page templates to custom folder?
- Is it possible to manipulate the list of page templates?
- Getting instance variable in scope of ‘wp_enqueue_scripts’
- wp_get_attachment_image_attributes not working for me
- How do I Make a Theme “plugin-ready”?
- How to Auto Approve Comments on a Specific Page?
- Identifying the priority of style.css so I can make a small CSS file load last
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- Returning Variables back into a template
- Page attribute template dropdown not displayed even the syntax is correct
- WordPress nav_menu_css_class theme filter is not being called
- inserting custom li class to wp_list_pages
- customizing the_password_form filter
- Change file name from wp_generate_attachment_metadata
- Creating multiple hooks for theme
- Add theme templates for child categories into the template hierarchy
- Where can I access my custom page template?
- How to add numeric slug for child page in WordPress 5.9?
- WordPress page templates in a directory
- Simple way to get two language WP site
- get_page_template returning nothing
- Load child template based on parent
- Single Page theme [closed]
- Custom metabox for custom page template
- How to add “Template” option in page attributes panel?
- Should I use add_filter for functions in function.php of the theme?
- Show notice just below the search form on the themes page
- Default image size not working
- Theme Development: Starter Content after hook
- How to display all subpages and short by year
- How to create a custom page(not a template) in a theme
- WordPress taxonomy and archive custom class
- Custom page template with custom fields
- WordPress custom taxonomy check box to dropdown
- how to setup custom content structures
- Filter categories used with Custom Structure Permalink
- How can I conditionally show different home page templates based on whether or not the user is logged in?
- How to wrap all titles generated by Gutenberg “Heading” block with tag
- What are the hooks in WordPress theme development?
- Unique design inside a specific category’s url
- Issue On Displaying Pages with Post Name Permalink
- What is the best way to build home pages with a lot of sections for distributable themes [closed]
- Templates dropdown not appearing using _s theme (underscores)
- tiny_mce_before_init: ‘exact’ => true has no effect
- Where to put custom page templates in theme?
- pre_get_comments or the_content filter
- How to add pages in wordpress using codes?
- Injecting pre-defined text from custom page template to editor
- How to conditionally add a wp_filter
- How to set default values for edit_post_link() in my theme?
- Custom theme template files
- Is it possible to have a Theme with built-in physical page files?
- Tiny MCE custom styles, and preview in the backend
- Trouble in creating a custom template on twentyeleven theme
- content filter (add_filter) for category description?
- ACF get_sub_field ALT TAG in the repeater doesn’t show
- How to register dynamic settings in WordPress Customizer?
- Unpublished Pages Failing To Appear On Custom Path
- Show Yoast SEO meta tags in Custom WordPress Templates (Theme)
- Alternative solution for script_loader_tag?
- Group several custom global page templates in sub-folder
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- Make a custom field in admin post.php read only
- Different stylesheet for different pages not working fully
- How do I remove p tag *insertions*? Disabling `wpautop` removes manual tags
- Create a variable with string, array or multiple values
- How to manipulate wordpress template tags’ output
- Can you create a custom page with content in the center already defined?
- Suppress the_content filter in a nested loop
- apply_filters to featured image
- Paginated WP_Query doesn’t return 404’s, even when posts don’t exist
- 404 on child page template
- Loop inside page template not working
- Add rel to all images in a post
- How can i display a 4 diferent themplate for the archive page
- DIV containing iframe disappears below break point of 992 in Oxygen Builder
- Is there a way to have WordPress autodetect page templates in the page-templates directory and any sub-folders?
- What is the point of using the front-page.php template? [closed]
- Add text when displying attribute with a hook on single product page