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?
- get_template_part vs action hooks in themes
- Theme Activate Hook
- Issues with title-tag and document_title_parts
- 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?
- Create “File-less” Page Template in Functions.php
- Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks
- 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
- Adding items to page template dropdown on Page Edit Screen
- How do I Make a Theme “plugin-ready”?
- What can I hook into after_setup_theme?
- Run shortcode before filters
- Adding Content Areas to Custom Page Template
- Add class to before_widget for all widgets with a dropdown and a counter
- 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]
- Trouble with conditional tags
- 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();?
- Pagination & get_pages?
- Returning Variables back into a template
- Page attribute template dropdown not displayed even the syntax is correct
- wp_enqueue_scripts not called on search page?
- WordPress nav_menu_css_class theme filter is not being called
- inserting custom li class to wp_list_pages
- customizing the_password_form filter
- Do I really need the div class entry?
- Page template across themes
- WordPress Genesis Child Theme Filter divs
- 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
- Disable front-page.php template
- Can I show all the template files that are being used on my site?
- How to add theme support?
- Implement content-nosidebar.php / content-leftsidebar.php
- Simple way to get two language WP site
- get_page_template returning nothing
- Load child template based on parent
- Should I use function_exists() and/or add_action() in theme development?
- Custom Field returning Numerical Value for Image rather than URL
- Multiple Page Templates & CSS
- When trying to override plugin’s function by theme, my filter executes two times, I want it to run only a single time
- Highest number of WordPress Custom Page Templates?
- Single Page theme [closed]
- Custom metabox for custom page template
- Why is the Page Template dropdown menu using the wrong file name?
- Single-level menu option? Another way?
- How to add “Template” option in page attributes panel?
- Should I use add_filter for functions in function.php of the theme?
- How to change database values on theme update
- What is the “correct” way to add hooks or similar PHP behavior to a blocktheme?
- 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
- Template selection area is not visible on page editor sidebar in wordpress twentty sixteen default theme
- Move default page templates to sub directory
- 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
- Theme Customizer not loading JS for live preview
- How can I conditionally show different home page templates based on whether or not the user is logged in?
- Dynamic menu links after header title
- How to wrap all titles generated by Gutenberg “Heading” block with tag
- What are the hooks in WordPress theme development?
- Load sidebar template just once to prevent multiple animations
- Replace single_template filter with what for default posts?
- Need help with adding templates (archives and sitemap) to WordPress child theme
- How to create first post, fifth post full width, rest in three columns and so on
- Unique design inside a specific category’s url
- How to rotate every letter in a title
- Issue On Displaying Pages with Post Name Permalink