', esc_attr( $widgetId ), esc_attr( $widgetClasses ) ); $params[0]['after_widget'] = '
'; $params[0]['before_title'] = '

'; $params[0]['after_title'] = '

'; return $params; } /** * Process block widget content to downgrade h2 headings to h4. * * Block widgets render their headings as

. * Inside a sidebar card, h2 is too large — replace with h4 for proper * visual hierarchy. * * @param string $content Widget block content. * @param array $instance Widget instance data. * @param \WP_Widget $widget Widget object. * @return string Modified content. */ public function processBlockWidgetContent( string $content, array $instance, \WP_Widget $widget ): string { if ( empty( $content ) ) { return $content; } // Replace

...

with

pairs. // Single regex ensures only headings with wp-block-heading class are // downgraded, preventing mismatched tags if a widget contains other h2s. $content = preg_replace( '/]*)>(.*?)<\/h2>/s', '$2

', $content ); return $content; } }