Make WordPress Core

Opened 8 weeks ago

Last modified 5 weeks ago

#62675 new defect (bug)

register new pattern catogory possible docs bug

Reported by: backit's profile backit Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords: reporter-feedback
Focuses: Cc:

Description

Hi,
in
https://developer.wordpress.org/themes/patterns/registering-patterns/#pattern-categories
the code to register a new pattern category does not work. Instead of "themeslug/custom" should be "themeslug_custom" both in functions.php and pattern file.
functions.php

<?php
add_action( 'init', 'themeslug_register_pattern_categories' );

function themeslug_register_pattern_categories() {
        register_block_pattern_category( 'themeslug_custom', array( 
                'label'       => __( 'Theme Name: Custom', 'themeslug' ),
                'description' => __( 'Custom patterns for Theme Name.', 'themeslug' )
        ) );
}

pattern file:

<?php
/**
 * Title: Hero
 * Slug: themeslug/hero
 * Categories: featured, themeslug_custom
 */
?>
<!-- Your block markup goes here. -->

Hope this is the right place (i did not find a bug document specific place)
Best regards.

Change History (2)

This ticket was mentioned in Slack in #core-test by oglekler. View the logs.


8 weeks ago

#2 @poena
5 weeks ago

  • Keywords reporter-feedback added

Hi @backit and welcome to the WordPress Trac!

Can you please reply with a more detailed description of what is not working?

When I copy paste the code in the example, the pattern category does exist and my pattern has the correct category name.

But if I go to Appearance > Editor > Patterns and select the specific pattern, the slug is themeslug%2Fcustom
If I duplicate the pattern, the slug is themeslug-custom.
If I select "Add new pattern" and select the category from the list, the slug is themeslug-custom

So I end up with patterns in two categories with the same name but with different slugs.

Using a prefix as part of a unique identifier is valid. I don't think that this is a documentation issue but a bug in the Site Editor.

If this is the case, then a new issue needs to be opened in the Gutenberg GitHub repository, and this ticket should then be closed.

Note: See TracTickets for help on using tickets.