#41392 closed defect (bug) (fixed)
Theme styles for Text widget do not apply to Custom HTML widget
Reported by: | westonruter | Owned by: | westonruter |
---|---|---|---|
Milestone: | 4.8.1 | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | Widgets | Keywords: | has-patch fixed-major |
Focuses: | Cc: |
Description
In #40907 we introduced a Custom HTML widget that is dedicated for showing HTML. This was added because the Text widget is now managed by TinyMCE (#35243) which can undesirably modify custom HTML added by a user. In #40951 some pointers were added to the Text widget when the user clicked on the Text tab to edit HTML or when they attempted to paste HTML into the Visual tab. These pointers direct the user to consider using the Custom HTML widget for adding arbitrary HTML, HTML which is not general content like a user may enter for post content, as in the post editor. So it is expected that users will be placing HTML that they would formerly have placed in the Text widget to instead place in the Custom HTML widget. A problem here for styling is that themes are targeting the .textwidget
to add the necessary styles for HTML that a user may put into such a widget. The Custom HTML widget has no such class name, and so it is currently not getting the proper styles in themes.
To fix this, an element with the same textwidget
class name needs to be added as a wrapper around the content in the Custom HTML widget.
Attachments (6)
Change History (18)
This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.
7 years ago
#7
@
7 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
#8
@
7 years ago
- Keywords fixed-major removed
I just realized that themes are not just targeting .textwidget
. They are _also_ selecting the parent element, .widget_text
.. And actually, core themes use both, about half and half.
Text widget looks like this in Twenty Seventeen: properly-styled-text-widget-in-twentyseventeen.png
The same HTML looks quite wrong in the Custom HTML widget in Twenty Seventeen: misstyled-custom-html-widget-in-twentyseventeen.png
The best way I can think of to fix this up is to inject the widget_text
class name to appear alongside the widget_custom_html
class name, like so when printing out:
-
src/wp-includes/widgets/class-wp-widget-custom-html.php
class WP_Widget_Custom_HTML extends WP_Widget { 75 75 */ 76 76 $content = apply_filters( 'widget_custom_html_content', $content, $instance, $this ); 77 77 78 // Inject the Text widget's container class name alongside this widget's class name for theme styling compatibility. 79 // $args['before_widget'] = str_replace( $this->id_base, " $this->id_base widget_text", $args['before_widget'] ); 80 78 81 echo $args['before_widget']; 79 82 if ( ! empty( $title ) ) { 80 83 echo $args['before_title'] . $title . $args['after_title'];
With 41392.0.diff the Custom HTML widget in custom-html-widget-lacking-styles.png looks the same as text-widget-with-styles-applied.png.