WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#13379 closed enhancement (fixed)

wp_nav_menu item classnames

Reported by: silencematters Owned by: 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 4 years ago.
13379.2.diff (692 bytes) - added by ryan 4 years ago.
page_item and page-item-$id back compat.

Download all attachments as: .zip

Change History (12)

comment:1 follow-up: nacin4 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.

comment:2 silencematters4 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.


comment:3 in reply to: ↑ 1 wpmuguru4 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.

comment:4 WraithKenny4 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?

comment:5 nacin4 years ago

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

comment:6 ryan4 years ago

#12812 adds more classes.

ryan4 years ago

comment:7 ryan4 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.

comment:8 ryan4 years ago

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

ryan4 years ago

page_item and page-item-$id back compat.

comment:9 ryan4 years ago

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

comment:10 ryan4 years ago

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