Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#13379 closed enhancement (fixed)

wp_nav_menu item classnames

Reported by: silencematters's profile silencematters Owned by: nacin's profile nacin
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords:
Focuses: Cc:

Description

When adding an existing PAGE as a menu-item, there is currently no way to target that menu-item.

Adding the page-slug as a classname to the menu-item when a PAGE is used would help, as would a classname that appears when on that given page.

Attachments (2)

13379.diff (804 bytes) - added by ryan 14 years ago.
13379.2.diff (692 bytes) - added by ryan 14 years ago.
page_item and page-item-$id back compat.

Download all attachments as: .zip

Change History (12)

#1 follow-up: @nacin
14 years ago

  • Owner set to nacin
  • Status changed from new to reviewing

I think part of the issue is where you draw the line. In addition to pages, there's also other post types, including posts and any custom types. Some are hierarchical, some are not. Then there's categories, again hierarchical (do we list parents in some way?), tags, and custom taxonomies.

I think doing it just for pages is a little narrow, if we're going to do it. Is doing it for all post types and taxonomies too much markup?

I imagine there's already a filter to achieve this as well. Patches and thoughts welcome.

#2 @silencematters
14 years ago

Good points. I agree that doing it just for just pages might be a bit narrow.

It might be the most flexible if defined as just adding the post-slug as a classname, which spans across many custom post-types and taxonomies.

The current list of classes on a menu-item are:

<li class="menu-item menu-item-type-post_type menu-item-object-page">

Adding one more classname would enable a world of styling possibilities.


#3 in reply to: ↑ 1 @wpmuguru
14 years ago

Replying to nacin:

I think part of the issue is where you draw the line.

I think doing it just for pages is a little narrow, if we're going to do it. Is doing it for all post types and taxonomies too much markup?

I imagine there's already a filter to achieve this as well. Patches and thoughts welcome.

I'd go with a filter, that way a custom post type or other plugin/theme can add classes through the filter. The only way the CSS will be there for the extra classes is through plugin/theme functions.

#4 @WraithKenny
14 years ago

How about handle the default post types and taxonomies with built in class names, and let customs get handled by plugin writers... is there an API for that?

#5 @nacin
14 years ago

I've been meaning to revisit this. At the very least pages deserve classes, along with a filter to handle the rest.

#6 @ryan
14 years ago

#12812 adds more classes.

@ryan
14 years ago

#7 @ryan
14 years ago

Patch adds menu-item-post_type-$id where $id is a post/page/attachment/any post type ID.

Also adds menu-item-taxonomy-$id where $id is a category/tag/any custom taxonomy type ID.

#8 @ryan
14 years ago

(In [14891]) Classes for posts and terms in the menus. see #13379

@ryan
14 years ago

page_item and page-item-$id back compat.

#9 @ryan
14 years ago

(In [14900]) Back compat menu classes. see #12812 #13379

#10 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed
Note: See TracTickets for help on using tickets.