WordPress.org

Make WordPress Core

Opened 19 months ago

Last modified 19 months ago

#24910 new enhancement

Adding a class field to the text widget

Reported by: walkinonwat3r Owned by:
Milestone: Awaiting Review Priority: normal
Severity: trivial Version:
Component: Widgets Keywords: dev-feedback
Focuses: Cc:

Description

The text widget is often used as a catch-all way to enter arbitrary HTML into widget areas. I think it would benefit from a HTML class entry field, which would allow theme designers/developers to apply custom styling at the <div class="widget"> level.

We already do this for body and post classes, and the same logic and benefits apply here.

One example use case that comes up on many client projects is social media links. I often want to add a custom background to the entire widget, not just the text area. Right now, if I want to do this, I need to either
a) Give up: Forego the background on the widget title, and just apply it to the text area.
b) Repetition/Overkill: Write a custom widget with exactly the same code as the text widget, just with one extra class.
c) Loss of dragability: Use nth-child to target the widget
d) Divorcing styling from meaning: Use the widget's ID

Being able to add a '.social-links' class to the widget, along with the content, would allow making targeted CSS changes over the entire widget, while requiring less specificity and eliminating the concern of losing widget-specific styles due to reordering or re-spawning the widget, as may occur with an :nth-child or ID-based solution.

Per-widget classes are more modular and more semantic. In terms of implementation, this could be handled the same as menu item classes, i.e. with a screen option to toggle the field's visibility. Ideally, I think all widget types should have this field, but the text widget is an especially strong case, since it can be used for so many different purposes.

Change History (2)

comment:1 @sabreuse19 months ago

I'd be in favor of this -- it's a problem I've run into with a number of client sites, and documenting "now grab the ID of that specific widget..." isn't as friendly as I'd like it to be.

Note: See TracTickets for help on using tickets.