WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/26/16 01:57:57 (9 months ago)
Author:
pento
Message:

Menus: Add the menu-item-home class to the static front page item.

When a site is using a static front page, and that page is in a menu, it isn't given the CSS class menu-item-home, contrary to the developer documentation.

An incorrect solution was originally added in [35272], and is now gone. Let us never speak of it again.

Props mdgl, adamsilverstein, welcher, pento.
Fixes #35272.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu-template.php

    r38882 r38940  
    335335 
    336336    $front_page_url = home_url(); 
     337    $front_page_id  = (int) get_option( 'page_on_front' ); 
    337338 
    338339    foreach ( (array) $menu_items as $key => $menu_item ) { 
     
    344345        $classes[] = 'menu-item-type-' . $menu_item->type; 
    345346        $classes[] = 'menu-item-object-' . $menu_item->object; 
     347 
     348        // This menu item is set as the 'Front Page'. 
     349        if ( 'post_type' === $menu_item->type && $front_page_id === (int) $menu_item->object_id ) { 
     350            $classes[] = 'menu-item-home'; 
     351        } 
    346352 
    347353        // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object 
     
    376382                $classes[] = 'page-item-' . $menu_item->object_id; 
    377383                $classes[] = 'current_page_item'; 
    378             } 
    379  
    380             if ( 'page_on_front' ) { 
    381                 $classes[] = 'menu-item-home'; 
    382384            } 
    383385 
Note: See TracChangeset for help on using the changeset viewer.