Skip to content

Instantly share code, notes, and snippets.

@DrewAPicture
Created February 8, 2013 22:29
Show Gist options
  • Save DrewAPicture/4742472 to your computer and use it in GitHub Desktop.
Save DrewAPicture/4742472 to your computer and use it in GitHub Desktop.
<?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
<option value="<?php echo esc_url(add_query_arg( array( 'action' => 'edit', 'menu' => $_nav_menu->term_id, ), admin_url( 'nav-menus.php' ) )); ?>" <?php if ( $nav_menu_selected_id == $_nav_menu->term_id ) echo 'selected="selected"'; ?>>
<?php
echo esc_html( $_nav_menu->truncated_name ) ;
if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
$locations_assigned_to_this_menu = array();
foreach ( array_keys( $menu_locations, $_nav_menu->term_id ) as $menu_location_key ) {
$locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
}
$assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) );
// Adds ellipses following the number of locations defined in $assigned_locations
printf( ' (%1$s%2$s)', implode( ', ', $assigned_locations ), count( $locations_assigned_to_this_menu ) > count( $assigned_locations ) ? ' &hellip;' : '' );
}
?>
</option>
<?php endforeach; ?>
@DrewAPicture
Copy link
Author

With a default of 3 passed to the array_slice and 4 locations assigned, we get this: http://cl.ly/image/2e2l3a0S2K0T

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment