Site icon Denis Bouquet

Change widget headings from h1 to h3 in WordPress

Recently, I had the bad surprise to find h1 heading titles in the widgets of my WordPress theme. Here is a small function to change those heading h1 to h3 (or another tag)

If you want a good SEO, you should have a unique h1 heading on each page of your website (6 years later, info not correct any more. You can now have more than one h1 per page. However, those widget titles probably don’t deserve a h1 tag).
To change the widget heading include the following code into your functions.php file in your active theme folder.


// CHANGES WIDGET HEADINGS TO H3 (INSTEAD OF H1)

add_action( 'after_setup_theme', 'remove_parent_theme_features', 10 );

function remove_parent_theme_features() {
	remove_action( 'init', 'sempress_widgets_init' );
	add_action( 'init', 'ph_sempress_widgets_init' );
}

function ph_sempress_widgets_init() {
  register_sidebar( array(
    'name' => __( 'Sidebar 1', 'sempress' ),
    'id' => 'sidebar-1',
    'before_widget' => '<section id="%1$s" class="widget %2$s">',
    'after_widget' => '</section>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
  ) );
}
Exit mobile version