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

Allow themes to add custom templates description #44097

Closed
iamtakashi opened this issue Sep 12, 2022 · 5 comments
Closed

Allow themes to add custom templates description #44097

iamtakashi opened this issue Sep 12, 2022 · 5 comments
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.

Comments

@iamtakashi
Copy link

iamtakashi commented Sep 12, 2022

Themes can add custom templates, but there doesn't seem to be a way to add descriptions. @jffng kindly looked into this for me, and it seemed like name, title, and postTypes are allowed at the moment.

The screenshot was from a site with Twenty Twenty-Two, but many other themes also have no way of clarifying the custom template. The description will help theme builders to communicate with the user what the custom templates are for.

I've briefly looked for a request opened before but couldn't find it. If there is somewhere, kindly point me to the conversation. Thanks in advance!

Screenshot 2022-09-12 at 17 01 06

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Feature] Templates API Related to API powering block template functionality in the Site Editor [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Sep 12, 2022
@github-actions
Copy link

Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Oct 13, 2022
@talldan talldan removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Oct 13, 2022
@iamtakashi
Copy link
Author

Thanks, @talldan, for removing the stale tag.

I still think it'd be helpful for both themers and users if we could add descriptions to custom templates.

@mikemcalister
Copy link

As we see more work happening on the Site Editor view, it would be great to see these descriptions added to help with consistency in the Template view.

Further, the ability to easily create templates within the admin means users may add more templates than they have historically. Having a way to describe these templates for themselves and other users will be a necessity.

@talldan
Copy link
Contributor

talldan commented Jan 9, 2023

justintadlock added a commit to x3p0-dev/x3p0-ideas that referenced this issue Jul 7, 2023
Core doesn't allow custom template descriptions via `theme.json`, so these must be added via PHP.

See: WordPress/gutenberg#44097
@fabiankaegy
Copy link
Member

Actually after investigating this a bit more the customTemplates key in theme.json isn't actually whats used for the title / description here. Instead it is this filterable list here: https://github.com/WordPress/wordpress-develop/blob/ca0260b5beaab6666e8f9fe0a9bff0ca8f6ac228/src/wp-includes/block-template-utils.php#L109-L184

So you can add your custom templates including description like so:

add_filter( 'default_template_types', 'add_custom_template_types', 10, 1 );

/**
 * Add custom template types.
 *
 * @param array $templates The default template types.
 *
 * @return array The modified template types.
 */
function add_custom_template_types( $templates ) {

	$templates['single-podcast'] = [
		'title'       => __( 'Single Podcast', 'namespace' ),
		'description' => __( 'A single podcast post.', 'namespace' ),
	];

	return $templates;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants