Make WordPress Core

Opened 8 weeks ago

Last modified 22 hours ago

#60881 new enhancement

Introduce 'template_name' label to custom post types and custom taxonomies

Reported by: aljullu's profile aljullu Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.1
Component: Editor Keywords: has-patch
Focuses: Cc:

Description

Currently, there is no way to add user-friendly names to block templates generated automatically from custom post types and custom taxonomies.

This ticket is about introducing a new label: 'template_name', which could be used to label templates in the Site Editor instead of the currently used single_name.

See https://github.com/WordPress/gutenberg/issues/60283 for more context.

Change History (2)

This ticket was mentioned in PR #6344 on WordPress/wordpress-develop by @aljullu.


8 weeks ago
#1

  • Keywords has-patch added

This PR is a follow-up of https://github.com/WordPress/gutenberg/pull/60367 to:

  1. Document the template_name label when registering post types and taxonomies.
  2. Add a default value.

## Testing steps

  1. Add this code snippet to your site. You can use the Code Snippets plugin:

{{{PHP
add_action( 'init', function () {

register_post_type(

'recipe',
array(

'labels' => array(

'name' => 'Recipes',
'singular_name' => 'Recipe',

),
'public' => true,
'show_in_rest' => true,

)

);
register_taxonomy(

'recipe_cat',
'recipe',
array(

'label' => 'Categories',
'labels' => array(

'name' => 'Recipe categories',
'singular_name' => 'Category',

),
'show_in_rest' => true,

)

);

} );
}}}

  1. Go to Appearance > Editor > Templates > Add new and verify there are no regressions in the Add template screen: two items related to the code snippet should appear there: _Single item: Recipe_ and _Category (recipe_cat)_.

https://github.com/WordPress/gutenberg/assets/3616980/c76df58d-2d87-4097-9e41-b2ec90a32c09

  1. Install Gutenberg and checkout this branch: https://github.com/WordPress/gutenberg/pull/60367.
  2. Repeat step 2 and verify there are no regressions.
  3. Now, modify the code snippet you created before, adding template_name to the post type and taxonomy:
add_action( 'init', function () {
        register_post_type(
                'recipe',
                array(
                        'labels'       => array(
                                'name'          => 'Recipes',
                                'singular_name' => 'Recipe',
+                               'template_name' => 'Single recipe',
                        ),
                        'public'       => true,
                        'show_in_rest' => true,
                )
        );
        register_taxonomy(
                'recipe_cat',
                'recipe',
                array(
                        'label'        => 'Categories',
                        'labels'       => array(
                                'name'          => 'Recipe categories',
                                'singular_name' => 'Category',
+                               'template_name' => 'Recipes by category',
                        ),
                        'show_in_rest' => true,
                )
        );
} );
  1. Repeat step 2 and verify the user-friendly template labels are shown:

https://github.com/WordPress/gutenberg/assets/3616980/57e675fc-7cf0-4c5c-9ad1-8afa9ef1302b

Trac ticket: https://core.trac.wordpress.org/ticket/60881

@ntsekouras commented on PR #6344:


22 hours ago
#2

Thanks for the PR! Can you create a trac ticket for this and link this PR?

Note: See TracTickets for help on using tickets.