Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to remove unnecessary Template Parts from core theme #39951

Open
ramizmanked opened this issue Mar 31, 2022 · 2 comments
Open

Ability to remove unnecessary Template Parts from core theme #39951

ramizmanked opened this issue Mar 31, 2022 · 2 comments
Labels
[Block] Template Part Affects the Template Parts Block [Type] Enhancement A suggestion for improvement.

Comments

@ramizmanked
Copy link
Contributor

What problem does this address?

With FSE, per best of my knowledge, we are unable to remove unnecessary/unwanted template-parts comes with default theme (i.e. TwentyTwentyTwo).

Recently I developed a website on top of TwentyTwentyTwo theme. I wanted to customize some parts of default theme so I created a child theme of TwentyTwentyTwo and started working on it. At later stage, I noticed there are unused template-parts I no longer needed and I started looking into ways to remove those but I didn't find any solution except removing it directly from parent TwentyTwentyTwo theme.

What is your proposed solution?

Overriding "templateParts" in child theme's theme.json should reflect on the Editor > Template Parts and it should allow modifying/deleting Template Parts.

@bph bph added [Type] Enhancement A suggestion for improvement. [Block] Template Part Affects the Template Parts Block labels Mar 31, 2022
@MatthiasReinholz
Copy link

@ramizmanked I agree, that removing template parts from the child theme could be useful. Especially, when you're building a parent theme with some kind of extensive parts library and you want to make the child theme as simple as possible to maintain for a client.

You're also mentioning "modifying" Template Parts. That's already possible. You can drop a template-part.html (with the similar file name used in the parent theme) to the /parts folder of your child theme. If you want to modify the title of the Template Part, you can additionally add it to the child theme's theme.json as if you wanted to register a new Template Part. As long as you're using the same name, it's not going to add a duplicate but alter the original one.

@rosa2
Copy link

rosa2 commented Sep 24, 2022

Yes, very necessary because I have 10 post types and I have made templates for each one, and besides the ones from my child theme, i have extra ones when you create or edit a post. And functions to unset templates doesn't work.

function child_remove_page_templates( $page_templates ) {
   unset( $page_templates['page-large-header'] );
   return $page_templates;
}
add_filter( 'theme_page_templates', 'child_remove_page_templates' );
add_filter( 'theme_post_templates', 'child_remove_page_templates' );

The page template gets unset (I tried with the print_r), but it still shows in the edit post page.
Please resolve this. I will try by JavaScript in the edit page to hide them.

And always thanks a lot for your work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants