How To Prevent Widget Titles Appearing On Your WordPress Site

How To Prevent Widget Titles Appearing On Your WordPress Site

The humble default WordPress Text widget is arguably one of the most flexible widgets but it has a flaw.

Give it a title for clarity in the Admin interface and it automatically gets output in your WordPress site.

In this quick article, I’ll show you how stop that automatic output and let you have your Admin clarity.

Composite image of admin interface and sidebar
Giving your Text widgets titles adds real clarity

The description of “add arbitrary text and HTML” shortchanges this widget’s capabilities as we all know that we can also include javascript and, with a bit of tweaking, shortcodes.

Screenshot of the Primary Sidebar with 3 text widget areas
What’s in each Text widget?

But the Text widget has been bugging me recently, especially when reviewing the theme builders where I often have three or four text widgets in a sidebar containing custom text and javascript for an ad server.

I wanted to give my widgets a title so I knew which was which but I didn’t necessarily want the titles being output in the public site (the default behavior).

The solution, it turns out, is dead simple and a mere three lines of code.

There are certain mantras that seem to always run true for WordPress one of which is “there’s a filter or action for that”. In this case, it’s a filter, more specifically the widget_title filter which is applied to every widget title before being output in a site’s sidebar or widget area.

Screen shot of same sidebar with titles on Text widgets
Clarity in Admin, hidden to public

To have my cake and eat it then, I needed some way of identifying that the title should not be output. I decided to go with wrapping the title in square brackets – [Admin interface only].

So, by hooking into the widget_title filter, I can check to see if the title is wrapped in [ ] and if it is then I’ll return an empty string, otherwise the original title is returned and ultimately displayed in the public site.

As this filter is not applied in the Admin interface, I still get my titles.

Here’s the code as a plugin. Save this as flexible-widget-titles.php in the wp-content/plugins folder of your site, go to Plugins and activate it.

* @package Flexible_Widget_Titles
* @version 1.0
Plugin Name: Flexible Widget Titles
Plugin URI:
Description: Wrap a widget title in [] to prevent it being displayed on your website
Author: Chris Knowles
Version: 1.0
Author URI:

function flexible_widget_titles( $widget_title ) {

// get rid of any leading and trailing spaces

$title = trim( $widget_title );

// check the first and last character, if [ and ] set the title to empty

if ( $title[0] == '[' && $title[strlen($title) - 1] == ']' ) $title = '';

return $title;


add_filter( 'widget_title', 'flexible_widget_titles' );


This has certainly made managing multiple Text widgets a lot easier for me. Hopefully you might find it useful too.