Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Creating a custom widget has me puzzled.

Hi,

I am busy creating a custom widget for a site that I am working on, but now I am suck/puzzled. The widget works, except that I have a text area which is making me puzzled.

In this text field I have used basic html, <h6> and <p> tags. My problem is that it is converting my HTML tags into special characters.

i have tried and google for far too long and I cant find a solution.

there are 3 points where I "interact" with the content from that textarea

form()

$content = isset($instance['content']) ? $instance['content'] : '';

update()

$instance['content'] = wp_kses($new_instance['content'], $allowed);
// also tried
$instance['content'] = ( ! empty( $new_instance['content'] ) ) ? strip_tags( $new_instance['content'], '<a><p><h1><h2><h3><h4><h5><h6><small><i><b>' ) : '';
// and
$instance['content'] = $new_instance['content']

widget()

$content = apply_filters('widget_content', $instance['content']);

I hope I have provided enough info to get help with this.

So after a few pints and a hangover I looked over everything and found the problem. It all came down to one little function that I slipped into the widget just before i echo the $content. I used esc_attr($content) which turned all my html tags into special characters.