-
-
Save billerickson/7bedd32df2dfc86b7030f38b0d3134b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function be_equal_sized_menu_items( $classes, $item, $args ) { | |
// Only run on the header menu | |
if( ‘top_menu’ !== $args->theme_location ) | |
return $classes; | |
// Only run on top level menu items | |
if( $item->menu_item_parent ) | |
return $classes; | |
// Grab all menu items | |
// Added lines | |
$menu_name = ‘top_menu’; | |
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) { | |
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] ); | |
} | |
// Changed line | |
$menu_items = wp_get_nav_menu_items($menu->term_id); | |
// Remove submenu items | |
foreach( $menu_items as $i => $menu_item ) | |
if( $menu_item->menu_item_parent ) | |
unset( $menu_items[$i] ); | |
// Count all top level items, and add as a class | |
$classes[] = ‘count-‘ . count( $menu_items ); | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment