20Apr

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 an unique h1 heading on each page of your website. To change the widget heading include the following code into your functions.php file in your 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>',
  ) );
}

5 thoughts on “Change widget headings from h1 to h3 in WordPress

  1. My widget-title is H1 and I used this code, doesn’t work and is still H1. I tried to include this in footer.php but nothing happens…
    my wordpress theme is OnlineMag by eVisionThemes and my problem is statistics widget which is located in website footer…

Leave a Reply