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

WordPress Trac noreply at wordpress.org
Mon Dec 16 08:38:23 UTC 2013


#26636: There Is No Filter For get_sidebar()
-------------------------+------------------------------
 Reporter:  shelob9      |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Template     |     Version:  1.5
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------------------
Changes (by SergeyBiryukov):

 * component:  General => Template


Old description:

> 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.

New description:

 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';
         }

         return $name;
 }
 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.

--

Comment:

 Related: #13239, #14310, #21062.

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


More information about the wp-trac mailing list