Skip to content

Instantly share code, notes, and snippets.

@markoheijnen
Last active December 10, 2015 14:38
Show Gist options
  • Select an option

  • Save markoheijnen/4448611 to your computer and use it in GitHub Desktop.

Select an option

Save markoheijnen/4448611 to your computer and use it in GitHub Desktop.
Give wp_nav_menu() a different class then default. In some cases themes style on the class 'menu'. What result in possible weird behavior.
<?php
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