I’m producing a child theme for wordpress. I’m trying to make it as fool proof as possible for the end users so would like to remove all the parent’s page templates so that they can’t be accidentally selected.
Is there a way to de-register them from the child themes functions or plugin? I know I could just go and delete them from the parent but that’s not update/upgrade proof.
Any help appreciated, thanks!
UPDATE 2019-06-10: At the time of writing this answer there was no good way of doing this, but since then the
theme_page_templates
andtheme_templates
hooks has been added, which makes this possible. From thetheme_page_templates
docs page:PREVIOUS ANSWER:
There are no filters available in
get_themes()
which is where WordPress locates the template files from the theme and parent theme in case one is used. Nor are there any filters available forget_page_templates()
orpage_template_dropdown()
. I would say your best option is to somehow remove or hide the option elements in the admin panel, preventing the user from choosing them.Hook onto the
admin_head
action and inject javascript or css to handle#page_template option[val=template-filename.php]
.Simply add empty templates, that have the same name and template header, in your child theme. Then include your own templates from within those template with
locate_template();
.I found the same question with more answers: https://wordpress.stackexchange.com/questions/13671/how-to-remove-a-parent-theme-page-template-from-a-child-theme
Note that some answers do not work for later versions of WordPress (like 3.8). WordPress 3.9 might have a hook that will allow developer to simply exclude or rename templates in the list.