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

7
Leave a Reply

3 Comment threads
4 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
  Subscribe  
newest oldest
Notify of

Hi, where should I paste it? Thanks!

jokerable

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…

Geenkaas

Why would a h3 be any better?