Repository navigation
Normalize theme tags to lowercase slugs when saving metadata - #891
Open
CookieDarb wants to merge 2 commits into
Open
CookieDarb wants to merge 2 commits into
CookieDarb wants to merge 2 commits into
Conversation
CookieDarb
marked this pull request as ready for review
October 19, 2026 14:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Closes #818
Fixes the issue where theme tags saved via the Create Block Theme plugin are output with capitalized letters or human-readable feature labels (e.g.,
Blog,Block Editor Styles,RTL-Language-Support) instead of lowercase, hyphenated slugs (blog,block-styles,rtl-language-support).Why?
When WordPress Core loads theme headers for the REST API (
/wp/v2/themes), it automatically translates tag slugs into human-readable display names (e.g.block-stylesbecomesBlock Editor Styles,full-site-editingbecomesSite Editor).The Create Block Theme metadata modal previously consumed
themeData.tags.rendered, populating the tag input field with these translated, capitalized strings. When the theme was saved, the backend wrote those strings directly tostyle.csswithout lowercasing or reverse-mapping display labels back to slugs. This resulted in invalid theme headers that failed WordPress Theme Directory review conventions.How?
includes/create-theme/theme-tags.php:get_label_to_slug_map()to map human-readable display labels (e.g."Block Editor Styles","Site Editor","Food & Drink") back to official Core feature slugs usingget_theme_feature_list().CBT_Theme_Tags::normalize_tags()to convert labels to official slugs, sanitize and lowercase custom tags withsanitize_title(), trim whitespace, and deduplicate entries.theme_tags_list()to pass all merged checkbox and custom tags throughnormalize_tags()before writing tostyle.css.is_active_theme_tag()to safely normalize active theme tags when checking defaults.includes/class-create-block-theme-api.php:theme_tagstoadd_additional_data_to_theme_response()so the REST API provides the active theme's raw, normalized slugs directly from$theme->get( 'Tags' ).src/editor-sidebar/metadata-editor-modal.js:getInitialThemeTags()helper to prioritize normalized slugs (themeData.theme_tags) with safe fallbacks, avoiding crashes and keeping tag tokens formatted as lowercase slugs.tests/test-theme-tags.php:normalize_tags()andtheme_tags_list(), verifying label mapping, custom slug lowercasing, string and array parsing, whitespace trimming, and deduplication.Testing Instructions
style.csshas tags defined (e.g.,Tags: blog, block-styles, full-site-editing).blog,block-styles,full-site-editing) rather than capitalized labels (Blog,Block Editor Styles,Site Editor).RTL-Language-Support) or a display label and save the theme.style.cssfile and verify all tags in theTags:header are written in canonical lowercase hyphenated format (e.g.Tags: blog, block-styles, full-site-editing, rtl-language-support).Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Investigating Core REST API tag formatting, suggesting changes and adding unit tests. Final decisions and edits were made by me.