Skip to content

Normalize theme tags to lowercase slugs when saving metadata - #891

Open
CookieDarb wants to merge 2 commits into
WordPress:trunkfrom
CookieDarb:fix/theme-tags-capitilization
Open

CookieDarb wants to merge 2 commits into
WordPress:trunkfrom
CookieDarb:fix/theme-tags-capitilization

Conversation

@CookieDarb

Copy link
Copy Markdown

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-styles becomes Block Editor Styles, full-site-editing becomes Site 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 to style.css without 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:
    • Added 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 using get_theme_feature_list().
    • Added CBT_Theme_Tags::normalize_tags() to convert labels to official slugs, sanitize and lowercase custom tags with sanitize_title(), trim whitespace, and deduplicate entries.
    • Updated theme_tags_list() to pass all merged checkbox and custom tags through normalize_tags() before writing to style.css.
    • Updated is_active_theme_tag() to safely normalize active theme tags when checking defaults.
  • includes/class-create-block-theme-api.php:
    • Added theme_tags to add_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:
    • Added 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:
    • Added unit test coverage for normalize_tags() and theme_tags_list(), verifying label mapping, custom slug lowercasing, string and array parsing, whitespace trimming, and deduplication.

Testing Instructions

  1. In an active block theme, ensure style.css has tags defined (e.g., Tags: blog, block-styles, full-site-editing).
  2. Open the Site Editor and launch the Create Block Theme sidebar.
  3. Click Edit Theme Metadata to open the modal.
  4. Verify the Theme tags field displays clean, lowercase slugs (blog, block-styles, full-site-editing) rather than capitalized labels (Blog, Block Editor Styles, Site Editor).
  5. Add a custom tag with mixed casing (e.g., RTL-Language-Support) or a display label and save the theme.
  6. Inspect the theme's style.css file and verify all tags in the Tags: 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.

@CookieDarb
CookieDarb marked this pull request as ready for review October 19, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create Block Theme: Theme tags are incorrectly capitalized when saving a theme

1 participant