WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 8 months ago

#19709 reopened enhancement

Add 'before_sidebar' and 'after_sidebar' attributes to register_sidebar()

Reported by: dgwyer Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.2
Component: Widgets Keywords:
Focuses: Cc:

Description

Whilst experimenting with some code recently I needed to have each widget area wrapped inside a container with the widget id as the container CSS class/id.

If used in a theme this widget area container usually has to be hard coded. This is the case for Twenty Ten, and Twenty Eleven.

It occurred to me that it would be very useful to have an extra couple of attributes available in register_sidebar() such as 'before_sidebar' and 'after_sidebar' so that developers have a consistent way to automatically add a wrapper to each widget area.

It would be additionally useful if you could do something like this to add the widget area id as the wrapper CSS class/id as required:

'before_sidebar' => '<div class="%3$s">'
'after_sidebar' => '</div>'

or

'before_sidebar' => '<div id="%3$s">'
'after_sidebar' => '</div>'

If this feature is considered then I'm not sure whether 'before_sidebar' or 'before_widget_area' is a better choice for the attribute name.

Change History (3)

comment:1 c3mdigital8 months ago

  • Resolution set to wontfix
  • Status changed from new to closed
  • Version changed from 3.3 to 2.2

My argument against this is that child themes would lose some flexibility styling sidebars. Currently they can override sidebar.php in a child theme and add any container wrapper attributes they want. This would make it very hard for a child theme to change the wrapper html. I'm closing as wont fix but if anyone has additional input or a case for this please reopen and it can be discussed further.

comment:2 markoheijnen8 months ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

I disagree on your argument that you will lose flexibility. It will add flexibility when we add a filter to register_sidebar(). So that way you don't need to overwrite it with a file and maybe even break a child theme when you update your parent theme.

comment:3 dgwyer8 months ago

The idea is to increase flexibility. The 'before_sidebar' and 'after_sidebar' fields would be optional so if left empty (default setting) parent/child themes could still define the sidebar wrapper tags explicitly in theme templates files.

Note: See TracTickets for help on using tickets.