[wp-trac] [WordPress Trac] #26636: There Is No Filter For get_sidebar()

WordPress Trac noreply at wordpress.org
Mon Dec 16 07:29:13 UTC 2013


#26636: There Is No Filter For get_sidebar()
-------------------------+-----------------------------
 Reporter:  shelob9      |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  1.5
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 Because there is no filter for get_sidebar it is not possible to change
 which sidebar is called conditionally from a plugin and there is no good
 way to do it in a theme.

 Here is an example use for the filter I am proposing to add:


 function slug_mobile_sidebar( $name ) {
 if ( wp_is_mobile() ) {
 $name = mobile;
 }
 }
 add_filter( 'the_sidebar', 'slug_mobile_sidebar');


 Yes, I could go through a theme and wrap every instance of get_sidebar()
 in some conditionals or create my own sidebar function. Both of these
 solutions are inadequate because they require modifying theme files that I
 might not want to modify. For example, if I was creating a child theme, I
 would have to add every template to it for either of these solutions to
 work. They also make my code much less portable.

 Adding a filter to get_sidebar would enable plugin developers to write
 similar functions to add mobile sidebars, to stick with the same example.
 If implemented from a plugin that function would of course require a
 template redirect so WordPress could load sidebar-mobile.php from the
 plugin if it didn't exist in the theme directory.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/26636>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list