Permalink
Browse files

Function to add slug to menu li classes

  • Loading branch information...
saltcod committed Jun 7, 2012
1 parent cd6c8b3 commit fc5ecb966b6f64cc29566e8a355dd8603ca1faef
Showing with 16 additions and 0 deletions.
  1. +16 −0 functions.php
View
@@ -43,6 +43,22 @@ function show_template() {
}
+/* Add slug to menu li classes */
+function add_slug_class_to_menu_item($output){
+ $ps = get_option('permalink_structure');
+ if(!empty($ps)){
+ $idstr = preg_match_all('/<li id="menu-item-(\d+)/', $output, $matches);
+ foreach($matches[1] as $mid){
+ $id = get_post_meta($mid, '_menu_item_object_id', true);
+ $slug = basename(get_permalink($id));
+ $output = preg_replace('/menu-item-'.$mid.'">/', 'menu-item-'.$mid.' menu-item-'.$slug.'">', $output, 1);
+ }
+ }
+ return $output;
+}
+add_filter('wp_nav_menu', 'add_slug_class_to_menu_item');
+
+
if ( ! function_exists( 'toolbox_setup' ) ):

0 comments on commit fc5ecb9

Please sign in to comment.