Using preg_replace to clean widget output HTML

The cleanest way to do it without breaking forwards compatibility would be to create your own widget, extending the widget class you want to fix. Strip it back to the bare essentials of constructor and the widget method (in which you fix the HTML), then attach a function to widgets_init after the original widget which registers your widget and deregisters the original.

Leave a Comment