WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
function update( $new_instance, $old_instance ) {
    if( current_user_can( 'unfiltered_html' ) ) {
        $new_instance['title']     = strip_tags( $new_instance['title'], '<small><span><b><br><a><strong>' );
        $new_instance['more_text'] = strip_tags( $new_instance['more_text'], '<div><span><strong><b>' );
    } else {
        $new_instance['title']     = strip_tags( $new_instance['title'] );
        $new_instance['more_text'] = strip_tags( $new_instance['more_text'] );

I for sure am Admin i checked i can unfiltered html. But when i do this in my widget as seen in a tut its not working. Wordpress outputs it transformed into htmlspecialchars.

any filter for that? Hope its not a global filter i just wan't to do it in some widgets.

Whats the purpose of the sanitising in wigets then when wordpress runs it trough filters anyway?

After thinking about it i just will do this globally, i let wp do its thing and after that i just convert back what i need. Maybe a better solution then to remove the default esc_html filter and replace it with wp_kses and just allowing some tags. This way you still can see everything typed in and nothing is stripped out. Well at least not at that level. The widget itself might strip it or not.

/** allow <small> tags inside widget titles */
add_filter( 'widget_title', function($title) {
    $title = str_replace('&lt;small&gt;', '<small>', $title);
    $title = str_replace('&lt;/small&gt;', '</small>', $title);
    return $title;
} );

and the widget can now allow the tag or even everything, wordpress converts everything to htmlcharacters anyway. So only will end up as real html.

share|improve this question
up vote 0 down vote accepted

If it's outputting it transformed into htmlspecialchars you could just decode it.

In your widget() function:

echo $before_title;
echo htmlspecialchars_decode( $title );
echo $after_title;
share|improve this answer
Thanks i after thinking about it i just go with the global filter. Guess i asked to early. I digged into WP a little and its the esc_html filter applied to the widget titles by default. I edit my solution in and just accept this even if i would not recommend to do that, just letting everything come through. – amy Jul 11 '12 at 3:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.