I'm currently creating a child theme in WordPress and I'm having trouble with template parts and custom templates from parent theme. In particular, I want to disable some of the template parts provided by the parent theme. However, since WordPress merges the JSON files of the parent and child themes, I can't simply "remove" the template parts I don't want to use.
I don't want to solve this problem by "brute force" aka PHP coding. I am trying to achieve this by simply moving files around within folders or editing theme.json
. Of course, changing the parent theme is out of the question.
Solved for custom templates
I've noticed that other users have a similar problem, but I've "somehow" solved the part of a problem in question here.
And here is the trick I used to solve it. To disable certain custom templates, I came up with a workaround. It involves specifying a dummy condition. For example, in the "postType" key, I use a value that ensures that the parent templates won't be displayed to the user. Here is how I implemented this:
"customTemplates": [
{
"name": "blank",
"title": "Blank Page
},
{
"name": "no-title",
"title": "Successfully removed",
"postTypes": [
"to-remove-parent-template-use-dummy-post-type"
]
},
{
"name "single.sidebar",
"title": "Sidebar page",
"postTypes": [
"post",
"page"
]
}
]
... and just like that, template no-title
is gone :)
Still no solution for template parts
However, I'm stuck when it comes to disabling template parts. Some of them I don't want to use, but these parts only consist of the keys name
, title
and area
. Since area
is predefined ("header", "footer" and "uncategorized") and cannot be freely chosen, I can't use the same trick as above.
Does anyone have any suggestions on how to disable certain template parts in a child theme using theme.json
in WordPress with Gutenberg? Any input would be greatly appreciated.