Making WordPress.org

Changeset 12990


Ignore:
Timestamp:
11/30/2023 10:37:12 PM (7 months ago)
Author:
coffee2code
Message:

Support Theme: Ensure menu link is marked as active if the link is for the current page, regardless of how the link was originally defined.

Props hiteshtalpada, coffee2code.
Fixes #7104.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/header.php

    r12369 r12990  
    5151                                <?php
    5252                                foreach ( $menu_items as $path => $text ) :
    53                                     $class = '';
    5453                                    $url = parse_url( $path );
     54
     55                                    // Check both host and path (if available).
     56                                    $is_same_host = ! empty( $url['host'] ) ? $url['host'] === $_SERVER['HTTP_HOST'] : true;
     57                                    $is_same_path = ! empty( $url['path'] ) && false !== strpos( $_SERVER['REQUEST_URI'], $url['path'] );
     58
     59                                    $class = ( $is_same_host && $is_same_path ) ? 'class="active" ' : '';
     60
    5561                                    if ( ! empty( $url['host' ] ) ) {
    5662                                        $url = esc_url( $path );
    5763                                    } else {
    58                                         $class = false !== strpos( $_SERVER['REQUEST_URI'], $url['path'] ) ? 'class="active" ' : '';
    5964                                        $url = esc_url( home_url( $path ) );
    6065                                    }
Note: See TracChangeset for help on using the changeset viewer.