[wp-trac] [WordPress Trac] #29463: Add filter in WP_Nav_Menu_Widget

WordPress Trac noreply at wordpress.org
Tue Sep 2 09:55:11 UTC 2014


#29463: Add filter in WP_Nav_Menu_Widget
-------------------------------+------------------------------
 Reporter:  cyman              |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Widgets            |     Version:  3.0
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:  administration
-------------------------------+------------------------------

Comment (by cyman):

 Thank you for a quick answer @johnbillion!

 Yes, I am aware of the `wp_nav_menu_args` filter and how to target
 specific menus with if clauses.

 However, this feels to me more a hack than elegant solution, especially in
 some cases (and I found other questioning the
 [[http://wordpress.stackexchange.com/questions/53950/add-a-custom-walkter-
 to-a-menu-created-in-a-widget|same thing elsewhere]]) when one'd like a
 specific menu classes or walker applied to all custom menus that appear in
 the sidebars.

 Example usecase: I use the Tw Bootstrap for creating the theme, so I would
 like to apply the [https://github.com/twittem/wp-bootstrap-navwalker|WP
 Bootstrap Navwalker] and some Bootstrap classes to all the sidebar menus.
 While I don't want to use the navwalker for the custom menu positions in
 my theme (for example main navigation in header and footer navigation).

 What I have to do now to achieve that is to register a new widget (which
 extends the `WP_Nav_Menu_Widget`) and define new `widget` method just to
 change the arguments of the `wp_nav_menu` function call. And then use
 `unregister_widget` to unregister default menu widget.

 It would be much easier to add a filter in a theme to change these
 arguments for the existing custom menu widget. That would also be more
 consistent how other widgets/functions in the file `default-widgets.php`
 have hooks applied, for example the `WP_Widget_Pages`:

 {{{
 wp_list_pages( apply_filters( 'widget_pages_args', array(
         'title_li'    => '',
         'echo'        => 0,
         'sort_column' => $sortby,
         'exclude'     => $exclude
 ) ) );
 }}}

 I hope I explained my point.

 I'll take a look at the SVN instructions (I use git daily, so I hope I
 don't have troubles) you linked to and create a patch file.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29463#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list