Make WordPress Core

Opened 12 years ago

Closed 9 years ago

#19851 closed enhancement (wontfix)

wp_dropdown_categories should add category slug as class to each option.

Reported by: jackreichert's profile jackreichert Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: Taxonomy Keywords: has-patch
Focuses: template Cc:


Portability is important for theme developers. With more and more developers using JS for enhanced functionality of their themes it's important to offer portable selectors for their use. Category ID's tend to change in the migration process, category names do not.

While it's important to keep the class clutter low, I believe adding the slug of a category as a class to each option in wp_dropdown_categories would be very helpful for developers.

I found this modification useful for a theme I was developing and offer this patch with hope that my solution may benefit other developers.

Attachments (2)

category-template.diff (1.5 KB) - added by jackreichert 12 years ago.
category-template.slug_as_value.patch (1.6 KB) - added by jackreichert 12 years ago.
Patch for alternative solution to problem (details in comment)

Download all attachments as: .zip

Change History (5)

12 years ago

Patch for alternative solution to problem (details in comment)

#1 @jackreichert
12 years ago

Perhaps a better solution would be to offer an option that replaces the option value with the category slug. Patch for this solution added (category-template.slug_as_value.patch)

Last edited 12 years ago by jackreichert (previous) (diff)

#2 @nacin
10 years ago

  • Component changed from Template to Taxonomy
  • Focuses template added

#3 @boonebgorges
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

The suggestion in comment 1 was implemented in [31006]. wp_dropdown_categories() now accepts a 'value_field' parameter, which allows the option values to be set as 'slug' (or any other term property) instead of the term ID. See #30306.

Since this provides a reliable way to render dropdowns in an ID-independent way, I'm going to mark this ticket as wontfix. If anyone has independent use cases for wanting slug-based classes on <option> elements, feel free to reopen with details.

Note: See TracTickets for help on using tickets.