[wp-trac] [WordPress Trac] #10976: Add $before_content and $after_content to widget options

WordPress Trac wp-trac at lists.automattic.com
Tue Jul 20 21:01:56 UTC 2010


#10976: Add $before_content and $after_content to widget options
-------------------------+--------------------------------------------------
 Reporter:  newkind      |        Owner:  azaozz  
     Type:  enhancement  |       Status:  reopened
 Priority:  normal       |    Milestone:  2.9     
Component:  Widgets      |      Version:          
 Severity:  normal       |   Resolution:          
 Keywords:  2nd-opinion  |  
-------------------------+--------------------------------------------------
Changes (by lancewillett):

 * cc: lance@… (added)


Comment:

 Replying to [comment:3 azaozz]:
 > It seems this can be added in the `widget` method for a simple widget.
 However adding it globally would not make sense for more complex widgets
 that output several different elements and don't have distinct `title` and
 `content`.

 Yes, this would only be for simple widgets. More complex widgets can
 generally be styled without a problem based on more complex the HTML
 output.

 Though many widgets do not need an extra wrapper element, some do. In
 those cases it would be helpful to have widget content before/after hooks
 available, but empty by default.

 Case in point: if you look at the default widgets in {{{/wp-includes
 /default-widgets.php}}} you'll see that at least two of the default
 widgets use an extra wrapper element around the widget content (calendar
 and tag cloud).

 The main benefits I see for adding in the hooks are:

  1. The ability to style only the widget content area (avoiding styling
 the title and overall widget wrapper).
  2. The ability to specifically target elements inside the widget content
 area.

 This happens often in themes where the widget has multiple block level
 elements, like a text widget with multiple paragraph elements. The last
 paragraph element in the widget content might have bottom margin, for
 example, and if you cannot target only the paragraph elements in the
 widget content area it's difficult to remove the bottom margin to ensure
 that the widgets themselves have consistent spacing.

 It is possible to target the last element with a {{{last:child}}}
 selector, but that isn't supported in older browsers, so having an HTML
 element is the only way to achieve this until all browsers support CSS3.

 As mentioned in the original ticket, the way themes address this now is to
 add in an extra {{{div}}} in the "after_title" hook and then close it with
 the "before_widget" -- the problem is that if the title is empty you end
 up with an improperly formed {{{div}}} element.

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


More information about the wp-trac mailing list