RevelationTravis

Clean WordPress Menu

May 2nd, 2012
5,842
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //Deletes all CSS classes and id's, except for those listed in the array below
  3. function custom_wp_nav_menu($var) {
  4.     return is_array($var) ? array_intersect($var, array(
  5.         //List of allowed menu classes
  6.         'current_page_item',
  7.         'current_page_parent',
  8.         'current_page_ancestor',
  9.         'first',
  10.         'last',
  11.         'vertical',
  12.         'horizontal'
  13.         )
  14.     ) : '';
  15. }
  16. add_filter('nav_menu_css_class', 'custom_wp_nav_menu');
  17. add_filter('nav_menu_item_id', 'custom_wp_nav_menu');
  18. add_filter('page_css_class', 'custom_wp_nav_menu');
  19.  
  20. //Replaces "current-menu-item" with "active"
  21. function current_to_active($text){
  22.     $replace = array(
  23.         //List of menu item classes that should be changed to "active"
  24.         'current_page_item' => 'active',
  25.         'current_page_parent' => 'active',
  26.         'current_page_ancestor' => 'active',
  27.     );
  28.     $text = str_replace(array_keys($replace), $replace, $text);
  29.         return $text;
  30.     }
  31. add_filter ('wp_nav_menu','current_to_active');
  32.  
  33. //Deletes empty classes and removes the sub menu class
  34. function strip_empty_classes($menu) {
  35.     $menu = preg_replace('/ class=""| class="sub-menu"/','',$menu);
  36.     return $menu;
  37. }
  38. add_filter ('wp_nav_menu','strip_empty_classes');
  39. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×