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>',
  ) );
}

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

Leave a Reply