Home / functions.php / Replace widget title with custom title and HTML
  • How to Replace widget title with custom title and HTML

    replace-widget-title-with-custom-title-and-html

    Adding this snippet to the functions.php will let you use a filter to replace the widget title with custom title and or html.

    wordpress snippet : PHP

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

    ( WordPress codex functions, hooks, in this snippet. )

    widget_title, add_filter,
  • Fred

    Doesn’t work for me.

    • http://wpsnipp.com Kevin Chard

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

  • zeke

    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…?