Skip to content

Instantly share code, notes, and snippets.

@andymagill
Created November 19, 2019 21:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymagill/72147df209ebd5fb656e22f574d536b3 to your computer and use it in GitHub Desktop.
Save andymagill/72147df209ebd5fb656e22f574d536b3 to your computer and use it in GitHub Desktop.
Remove injected classes and ID's from navigation - WordPress
<?php
// Remove Injected classes, ID's and page ID's from navigation <li> items
function remove_nav_classes( $var ) {
if ( is_array( $var ) ) {
foreach ( $var as $key => $val ) {
if ( strpos( $val, 'item' ) > -1 && $val != 'current-menu-item' ) {
unset( $var[$key] );
}
}
return $var;
}
else {
return '';
}
}
add_filter('nav_menu_css_class', 'remove_nav_classes', 100, 1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment