Replace Widget Title with Custom Title and HTML

Snippets by IsItWP

WordPress widgets pick up the title that you define in the widgets section. You can replace widget title with custom title and HTML.

Instructions: Add the following code to the functions.php file of your WordPress theme.
You need to replace the text in the code below for a custom widget title.

add_filter('widget_title', 'change_widget_title', 10, 3);
function change_widget_title($title, $instance, $wid){       
    return $title = str_replace('Widget Title', '<span style="color: red">Custom</span>', $title);

You may also enjoy styling widget based on their position in a widget area.

Comments   Leave a Reply

  1. How I can change the H for the widget title? I have my titles at H5 and I want to have it at H3

    1. This is likely dependent on the theme. You may want to create a child theme.

  2. Greetings Kevin…is it possible to configure this to rename multiple instances of a widget that all have the same core name…using numerous ‘links’ widgets for categorization…WP 3.2.1…?

  3. Doesn’t work for me.

    1. what is your version of wordpress? are you getting an error if so what is the error you get?

      1. Doesn’t work for me either it is just showing the txt as test in the front end:

        1. PHP code can’t be added to Custom HTML widget. You may want to check out this guide on how to add PHP using a plugin: https://www.isitwp.com/properly-add-code-snippets-wordpress-site/

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!