• Skip to main content
  • Skip to primary sidebar

WP Dev

Guides, plugins and themes for WordPress

You are here: Home / General / Replace WordPress Widget Title Tag

Replace WordPress Widget Title Tag

February 25, 2023 by Ciprian Tepes Leave a Comment

Why would you need to replace the WordPress widget’s title tag?

There are situations when you purchase a theme or get a free theme that was created without any SEO in mind so the widgets title tags are either an h2 or an h3 and you certainly don’t want that.

How can you replace the WordPress widget title tag?

If you want to change the heading h1-h6 tags to a paragraph for SEO purposes in any genesis framework theme then you can use the following php function:

Where to add the php code so change the WordPress widget title tag?

You have a couple of options but here are two that work:

Option 1: Modify your theme or child theme’s functions.php file

Using your preferred method — an FTP program like FileZilla FTP or Transmit App or any other file manager (even cPanel’s file management works fine) — look for your functions.php file which usually is in wp-content/themes/[your-theme or your-child-theme]/functions.php

Edit your theme’s functions.php file and insert the code there

Option 2: Install the Code Snippets plugin from WordPress.org

  1. Go to Plugins -> Add New and search for Code Snippets, install and activate it;
  2. In WP Admin go to Snippets -> Add New (in the sidebar on the left);
  3. Add a snippet name (I chose “Custom widget heading tag”) and paste the code:
  4. Make sure you run the snippet everywhere (have that option selected)
Screenshot of Code Snippets plugin with the code needed for replacing the WordPress widget title tag

Change WordPress’ widget title to h2 or other html tag using the php code below

<?php
// php function to replace all widgets titles to paragraphs
add_action( 'after_setup_theme', function() {
  add_action( 'register_sidebar, function( $sidebar ) {
    global $wp_registered_sidebars;
    Sid = $sidebar['id'];
    $tag = 'p'; // replace this to anything you wish

    $sidebar[ 'before_title' ] = sprintf('<%s class="widget-title subheading heading-size-3">', $tag);
    $sidebar[ 'after_title' ] = sprintf('</%s>', $tag);

    $wp_registered_sidebars[ $id ] = $sidebar;
  )):
));

Now you have to inspect your front-end code to make sure the widget title tag was updated.

Filed Under: General

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Fix mariadb ERROR 2002 (HY000): Can’t connect to local server through socket ‘/tmp/mysql.sock’ (2) on macOS Monterey 12.6 using homebrew
  • Fix WordPress login redirect loop when accessing wp-admin
  • Fix easyengine error for global-nginx-proxy
  • Replace WordPress Widget Title Tag

Recent Comments

No comments to show.

Copyright © 2023 WP Dev · Powered by WordPress

Last Updated on 7 months by admin