WordPress.org

Make WordPress Core

Ticket #15954: root_relative_current.patch

File root_relative_current.patch, 999 bytes (added by WraithKenny, 3 years ago)

Give current-menu-item class even if the link is root relative

  • wp-includes/nav-menu-template.php

     
    363363                        $current_url = untrailingslashit( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); 
    364364                        $item_url = untrailingslashit( strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url ); 
    365365                        $_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) ); 
     366                        $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); 
    366367 
    367                         if ( in_array( $item_url, array( $current_url, $_indexless_current ) ) ) { 
     368                        if ( in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) { 
    368369                                $classes[] = 'current-menu-item'; 
    369370                                $menu_items[$key]->current = true; 
    370371                                $_anc_id = (int) $menu_item->db_id;