Have you ever wanted to do a little something extra special with a sidebar widget title?
If you have, you quickly learn that WordPress strips out all of the HTML tags, making it absolutely impossible to do so.
But there’s a way. 😉
With this snippet, you can add some bold and italics text awesomeness if you like (or other HTML tags for that matter).
Here’s how:
How-To Add Simple HTML in a WordPress Widget Title
As with most WordPress snippets, you’ll want to drop this bit of code in your functions.php theme file or create/add this to a functionality plugin.
Here’s the snip:
function html_widget_title( $title ) {
//HTML tag opening/closing brackets
$title = str_replace( '[', '$title = str_replace( '[/', '
//
$title = str_replace( ‘s]’, ‘strong>’, $title );
//
$title = str_replace( ‘e]’, ’em>’, $title );
return $title;
}
add_filter( ‘widget_title’, ‘html_widget_title’ );
?>
And that’s it!
This example will take care of your bold and italics, but you can play around and add other HTML tags, too!
Have fun!
[via WP-Snippets]
TechnoKnol says
I was looking for this.
Here is the modified version for to allow all HTML Tags.
// Allow HTML tags in Widget title
function html_widget_title( $var) {
$var = (str_replace( ‘[‘, ”, $var ));
return $var ;
}
add_filter( ‘widget_title’, ‘html_widget_title’ );
// Apply Tag in title like this
Widget_Title[span class=class_without_quote ]title_in_span[/span]