Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Created May 7, 2011 22:26
Show Gist options
  • Save franz-josef-kaiser/960910 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/960910 to your computer and use it in GitHub Desktop.
How-to: Alter nav menu output (in this case adding blueprint css classes)
<?php
/**
* Classes for a navigation named "Topnav" in the nav location "top".
*
* You will have to re-create this function inside your Child Theme.
* Just edit the data - "editing" comments - inside your Child Themes function.
*
* @since 0.1
* @since 0.2 - replaced by the new function that saves 24(!) queries.
*
* @param (object) $items
* @param (object) $menu
* @param (object) $args
* @return (object) $items
*/
function oxo_nav_top_classes( $items, $menu, $args )
{
// avoid destroying the admin UI
if ( is_admin() )
return;
# >>>> start editing
// Nav menu name you entered in the admin-UI > Appearance > Menus (Add menu).
$target['name'] = 'Topnav';
// The targeted menu item/s
$target['items'] = array( (int) 6 );
# <<<< stop editing
// filter for child themes: "config_nav_menu_topnav"
$target = apply_filters( 'config_nav_menu_'.strtolower( $target['name'] ), $target );
// Abort if we're not with the named menu
if ( $menu->name !== $target['name'] )
return;
foreach ( $items as $item )
{
// Add the class for each menu item
$item->classes = 'span-4';
// Append this class if we are in one of the targeted items
if ( in_array( (int) $item->menu_order, $target['items'] ) )
$item->classes .= ' last';
}
return $items;
}
add_filter( 'wp_get_nav_menu_items', 'oxo_nav_top_classes', 10, 3 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment