Skip to content

Instantly share code, notes, and snippets.

@technoknol
Last active April 19, 2021 09:46
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save technoknol/9526784 to your computer and use it in GitHub Desktop.
Wordpress - Allow HTML tags in Widget Title - No Plugin Required
<?php
/*
* Author : TechnoKnol
* Blog : http://technoknol.blogspot.com
* Purpose : Allow HTML tags in Widget Title in WordPress
*
* */
// Add below code in your theme's functions.php file
// Allow HTML tags in Widget title
function html_widget_title( $var) {
$var = (str_replace( '[', '<', $var ));
$var = (str_replace( ']', '>', $var ));
return $var ;
}
add_filter( 'widget_title', 'html_widget_title' );
// Usage : Use Forum type BB code styling just replace < & > with [ and ]
// If you wanna give class to tag , Apply without Quote.
// See Example Below.
Title with[span class=class_without_quote ]span Tag[/span]
@Limpuls
Copy link

Limpuls commented Feb 15, 2018

There is no spacing after the span tag. The next word is close to the last word in the span and space is not available.

@bfiessinger
Copy link

To use multiple classes you can use:
$var = (str_replace( '&#8220;', '"', $var));
and keep using " in your "HTML"

@YIN-Renlong
Copy link

useful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment