Create a gist now

Instantly share code, notes, and snippets.

Give wp_nav_menu() a different class then default. In some cases themes style on the class 'menu'. What result in possible weird behavior.
class Nav_Menu_Widget_Classname {
public function __construct() {
add_action( 'widget_display_callback', array( $this, 'menu_different_class' ), 10, 2 );
public function menu_different_class( $settings, $widget ) {
if( $widget instanceof WP_Nav_Menu_Widget )
add_filter( 'wp_nav_menu_args', array( $this, 'wp_nav_menu_args' ) );
return $settings;
public function wp_nav_menu_args( $args ) {
remove_filter( 'wp_nav_menu_args', array( $this, 'wp_nav_menu_args' ) );
if( 'menu' == $args['menu_class'] )
$args['menu_class'] = apply_filters( 'nav_menu_widget_class', 'menu_widget');
return $args;
$GLOBALS['nav_menu_widget_classname'] = new Nav_Menu_Widget_Classname();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment