Is there a reason get_header/sidebar/footer() do nothave filters?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there a reason get_header/sidebar/footer() do nothave filters?

Josh Pollock
I recently went looking for the filter to change which sidebar is outputted
and was a little shocked to find there are no filters in get_sidebar() or
in get_header() and get_footer(). Does anyone know if this was a conscious
choice or not? If so, what was the reason?

I'd be happy to write a patch to add some, but I'm wondering if there is
some valid reason I'm missing for not using them?

What I really want to be able to do is something like this:

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

This would allow me to add different markup to the sidebar on mobile, to
change its size, location, use a jQuery plugin to make the sidebar slide in
and out, etc. I could also change which widget area is shown or show no
sidebar at all.

Thanks,
Josh
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Is there a reason get_header/sidebar/footer() do nothave filters?

John Blackbourn
+1.

http://core.trac.wordpress.org/ticket/20287


On 10 December 2013 23:03, Josh Pollock <[hidden email]> wrote:

> I recently went looking for the filter to change which sidebar is outputted
> and was a little shocked to find there are no filters in get_sidebar() or
> in get_header() and get_footer(). Does anyone know if this was a conscious
> choice or not? If so, what was the reason?
>
> I'd be happy to write a patch to add some, but I'm wondering if there is
> some valid reason I'm missing for not using them?
>
> What I really want to be able to do is something like this:
>
> `
> function mobile_sidebar( $name ) {
> if ( wp_is_mobile() ) {
>      $name = mobile;
>   }
> }
> add_filter( 'the_sidebar', 'mobile_sidebar');
> `
>
> This would allow me to add different markup to the sidebar on mobile, to
> change its size, location, use a jQuery plugin to make the sidebar slide in
> and out, etc. I could also change which widget area is shown or show no
> sidebar at all.
>
> Thanks,
> Josh
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Is there a reason get_header/sidebar/footer() do nothave filters?

Otto-19
In reply to this post by Josh Pollock
On Tue, Dec 10, 2013 at 5:03 PM, Josh Pollock <[hidden email]> wrote:

> I recently went looking for the filter to change which sidebar is outputted
> and was a little shocked to find there are no filters in get_sidebar() or
> in get_header() and get_footer(). Does anyone know if this was a conscious
> choice or not? If so, what was the reason?
>
> I'd be happy to write a patch to add some, but I'm wondering if there is
> some valid reason I'm missing for not using them?
>
> What I really want to be able to do is something like this:
>
> `
> function mobile_sidebar( $name ) {
> if ( wp_is_mobile() ) {
>      $name = mobile;
>   }
> }
> add_filter( 'the_sidebar', 'mobile_sidebar');
> `
>
> This would allow me to add different markup to the sidebar on mobile, to
> change its size, location, use a jQuery plugin to make the sidebar slide in
> and out, etc. I could also change which widget area is shown or show no
> sidebar at all.
>
>
I'm assuming you'd do this in the theme, since it doesn't make a lot of
sense in a plugin (because the plugin would not have any idea about how the
theme's header/footer/sidebar is structured).

So, instead of just calling get_sidebar, why not do this instead?

if ( wp_is_mobile() ) {
  get_sidebar('mobile');
} else {
  get_sidebar();
}

Or something like that? A filter on these doesn't really add any
functionality that isn't relatively trivial to simply do elsewhere in the
theme, and again, it doesn't make a whole lot of sense for a plugin to do
this sort of thing without intimate theme knowledge to begin with.

-Otto
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Is there a reason get_header/sidebar/footer() do nothave filters?

Josh Pollock
Otto-

That's a good point, but I don't want to have to do that for every single
template, so instead I replace get_sidebar() with my own function that
calls get_sidebar if !wp_is_mobile() . This especially sucks for child
themeing, Also I might do this in a plugin and do a template redirect to
load mobile-sidebar.php from the plugin directory, if it doesn't exist in
theme.

On Tuesday, December 10, 2013, Otto wrote:

> On Tue, Dec 10, 2013 at 5:03 PM, Josh Pollock <[hidden email]<javascript:;>>
> wrote:
>
> > I recently went looking for the filter to change which sidebar is
> outputted
> > and was a little shocked to find there are no filters in get_sidebar() or
> > in get_header() and get_footer(). Does anyone know if this was a
> conscious
> > choice or not? If so, what was the reason?
> >
> > I'd be happy to write a patch to add some, but I'm wondering if there is
> > some valid reason I'm missing for not using them?
> >
> > What I really want to be able to do is something like this:
> >
> > `
> > function mobile_sidebar( $name ) {
> > if ( wp_is_mobile() ) {
> >      $name = mobile;
> >   }
> > }
> > add_filter( 'the_sidebar', 'mobile_sidebar');
> > `
> >
> > This would allow me to add different markup to the sidebar on mobile, to
> > change its size, location, use a jQuery plugin to make the sidebar slide
> in
> > and out, etc. I could also change which widget area is shown or show no
> > sidebar at all.
> >
> >
> I'm assuming you'd do this in the theme, since it doesn't make a lot of
> sense in a plugin (because the plugin would not have any idea about how the
> theme's header/footer/sidebar is structured).
>
> So, instead of just calling get_sidebar, why not do this instead?
>
> if ( wp_is_mobile() ) {
>   get_sidebar('mobile');
> } else {
>   get_sidebar();
> }
>
> Or something like that? A filter on these doesn't really add any
> functionality that isn't relatively trivial to simply do elsewhere in the
> theme, and again, it doesn't make a whole lot of sense for a plugin to do
> this sort of thing without intimate theme knowledge to begin with.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> [hidden email] <javascript:;>
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Is there a reason get_header/sidebar/footer() do nothave filters?

Josh Pollock
Finally getting a chance to work on this after a busy week.

I created a ticket and a patch:
http://core.trac.wordpress.org/ticket/26636

This is my first time adding a filter to WordPress so I'd appreciate it if
anyone has any feedback or advice.


On Wed, Dec 11, 2013 at 4:17 AM, Josh Pollock <[hidden email]> wrote:

> Otto-
>
> That's a good point, but I don't want to have to do that for every single
> template, so instead I replace get_sidebar() with my own function that
> calls get_sidebar if !wp_is_mobile() . This especially sucks for child
> themeing, Also I might do this in a plugin and do a template redirect to
> load mobile-sidebar.php from the plugin directory, if it doesn't exist in
> theme.
>
>
> On Tuesday, December 10, 2013, Otto wrote:
>
>> On Tue, Dec 10, 2013 at 5:03 PM, Josh Pollock <[hidden email]>
>> wrote:
>>
>> > I recently went looking for the filter to change which sidebar is
>> outputted
>> > and was a little shocked to find there are no filters in get_sidebar()
>> or
>> > in get_header() and get_footer(). Does anyone know if this was a
>> conscious
>> > choice or not? If so, what was the reason?
>> >
>> > I'd be happy to write a patch to add some, but I'm wondering if there is
>> > some valid reason I'm missing for not using them?
>> >
>> > What I really want to be able to do is something like this:
>> >
>> > `
>> > function mobile_sidebar( $name ) {
>> > if ( wp_is_mobile() ) {
>> >      $name = mobile;
>> >   }
>> > }
>> > add_filter( 'the_sidebar', 'mobile_sidebar');
>> > `
>> >
>> > This would allow me to add different markup to the sidebar on mobile, to
>> > change its size, location, use a jQuery plugin to make the sidebar
>> slide in
>> > and out, etc. I could also change which widget area is shown or show no
>> > sidebar at all.
>> >
>> >
>> I'm assuming you'd do this in the theme, since it doesn't make a lot of
>> sense in a plugin (because the plugin would not have any idea about how
>> the
>> theme's header/footer/sidebar is structured).
>>
>> So, instead of just calling get_sidebar, why not do this instead?
>>
>> if ( wp_is_mobile() ) {
>>   get_sidebar('mobile');
>> } else {
>>   get_sidebar();
>> }
>>
>> Or something like that? A filter on these doesn't really add any
>> functionality that isn't relatively trivial to simply do elsewhere in the
>> theme, and again, it doesn't make a whole lot of sense for a plugin to do
>> this sort of thing without intimate theme knowledge to begin with.
>>
>> -Otto
>> _______________________________________________
>> wp-hackers mailing list
>> [hidden email]
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers