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>',
  ) );
}
Subscribe
Notify of
7 Comments
Oldest
Newest
Inline Feedbacks
View all comments
3 years ago

Hi, where should I paste it? Thanks!

jokerable
3 years ago

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…

jokerable
3 years ago
Reply to  Denis

I know. it was just test (bad test).
I did as you said but my title is still H1 which. here’s snapshot:

http://s9.picofile.com/file/8307962742/2017_10_02_12_46_14.png

Geenkaas
2 years ago

Why would a h3 be any better?