# Use Real Headings for Widget Titles

> Makes classic sidebar widget titles proper H2 headings, so screen reader users can jump between widgets with heading navigation.

- Type: PHP
- Runs: Run everywhere
- Category: [Accessibility](https://wpide.com/library/category/accessibility/)
- Tags: widgets, headings, sidebar
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/a11y-widget-titles-as-headings/

## Code

```php
// Heading level used for widget titles.
$wpide_widget_heading = 'h2';

add_filter( 'dynamic_sidebar_params', function ( $params ) use ( $wpide_widget_heading ) {
    if ( empty( $params[0] ) || ! is_array( $params[0] ) ) {
        return $params;
    }

    $tag = tag_escape( $wpide_widget_heading );

    if ( isset( $params[0]['before_title'] ) && ! preg_match( '#^\s*<h[1-6]#i', $params[0]['before_title'] ) ) {
        $params[0]['before_title'] = '<' . $tag . ' class="widget-title widgettitle">';
        $params[0]['after_title']  = '</' . $tag . '>';
    }

    return $params;
} );
```

## Notes

Change $wpide_widget_heading to h3 if your theme already uses H2 for the main sections around the sidebar.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Use Real Headings for Widget Titles" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
