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

Issue with Registering a Pattern Category – Slug Conversion Creates Duplicate Categories #1836

Open
jigneshnakrani088 opened this issue Feb 6, 2025 · 1 comment
Labels
[Status] To do Issue marked as Todo

Comments

@jigneshnakrani088
Copy link

Issue Description

The example provided in the Registering a Pattern Category documentation is incorrect because WordPress does not support / in slugs. Instead, it automatically converts / to -, leading to unintended duplicate categories.

URL of the Page with the Issue

https://developer.wordpress.org/themes/patterns/registering-patterns/#registering-a-pattern-category

Section of Page with the issue

Registering a Pattern Category

Why is this a problem?

Suggested Fix

Try adding a new custom pattern category for your theme. Add this code to your theme’s functions.php file:

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' )
	) );
}

Now try adding the themeslug-custom category to any block pattern:

<?php
/**
 * Title: Hero
 * Slug: themeslug/hero
 * Categories: featured, themeslug-custom
 */
?>
<!-- Your block markup goes here. -->
@jigneshnakrani088 jigneshnakrani088 added the [Status] To do Issue marked as Todo label Feb 6, 2025
Copy link

github-actions bot commented Feb 6, 2025

Heads up @WordPress/docs-issues-coordinators, we have a new issue open. Time to use 'em labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] To do Issue marked as Todo
Projects
None yet
Development

No branches or pull requests

1 participant