[wp-trac] [WordPress Trac] #41239: Add filter in dynamic_sidebar() to allow changing the index before rendering

WordPress Trac noreply at wordpress.org
Wed Jul 5 00:24:51 UTC 2017


#41239: Add filter in dynamic_sidebar() to allow changing the index before
rendering
-------------------------------+------------------------------
 Reporter:  jantank            |       Owner:
     Type:  feature request    |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Widgets            |     Version:  trunk
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Comment (by westonruter):

 @jantank my thoughts on how to implement this with the `sidebars_widgets`
 filter would be to use it to swap out the widgets used for a given sidebar
 at runtime. This may actually not work with how widgets are managed in the
 Customizer, but the idea is that you could have something like this:

 {{{#!php
 <?php
 add_filter( 'sidebars_widgets', function( $sidebars_widgets ) {
     if ( myplugin_is_microsite1() ) {
         $sidebars_widgets['footer'] =
 $sidebars_widgets['microsite1_footer'];
     }
     return $sidebars_widgets;
 } );
 }}}

 And then in your template you still have just `dynamic_sidebar( 'footer'
 )` but then depending on which URL you are currently on you see different
 widgets in the footer sidebar.

 Again, this probably won't work at the moment in the Customizer because
 the `microsite1_footer` sidebar would never be directly used and thus its
 customizer section would never appear, but that would change with #40432
 when inactive sidebar sections are displayed.

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


More information about the wp-trac mailing list