Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://www.wpreso.com/blog/tutorials/2011/01/04/add-pagepost-slug-class-to-menu-item-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');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement