Subscribe to my RSS feed RSS
May 11, 2007

How do I display a WordPress Widget without a title?

  • Written by Owen under blogging |
  • 5 comments already |

Help! My WordPress theme uses Widgets and I’m getting a big white space in between widgets. What is this and how can I remove this?

Elizabeth down at Table for Five asked the question above as her blog had some ugly white space in the sidebar and she just couldn’t figure out how to get rid of it. Her page appeared like this:

whitespace.JPG

note the white space marked with the red marker.

Turns out that she is using Widgets on the site and the area below the white space consists of a Text widget. The thing about this widget is that it has no title, so the widget code creates a big white space instead of this. How can this be fixed?

The answer is to update the widget code and enable it to handle blank headers in a more graceful manner. Here’s how to do this:

  • Click on your Plugins Menu and choose Edit Plugin.
  • Select the Sidebar Widgets plugin for editing
  • Search for “function widget_text” and this should take you to the following function:


function widget_text($args, $number = 1) {
extract($args);
$options = get_option('widget_text');
$title = $options[$number]['title'];
if ( empty($title) )
$title = ‘ ‘;

  • Change the line $title = ‘ ‘; to $title =”; (that’s 2 x single quotes)
  • Click Update File to save the plugin

Switch back to viewing your site and you should see that the problem has been fixed.

Please Note: The change above involves direct changes to your widget.php file. Please make sure that you have a backup of your plugin folder before you do this.

Feed for this Entry | Trackback Address

5 comments already

  1. Chris Merriman on 05.11.2007 at 7:00 am | permalink
  2. Not quite sure what I’ve done wrong, but I end up with

    Parse error: syntax error, unexpected T_STRING in /home/chrismer/public_html/wp-content/plugins/widgets/widgets.php on line 834

    I tried entering the amendment manually at first, using two ‘
    then I tried ” - a single quotation mark
    then I tried copying’n'pasting your amendment

    call resulted in the error above, assuming it posts again.
    Any chance you could let me know where I’ve gone wrong?

  3. Chris Merriman on 05.11.2007 at 7:06 am | permalink
  4. scrap that, apologies, feel free to remove both these comments.

    Looks like I initially used a double quotation mark, and my subsequent edits weren’t written to the file - when I FTPed in and edit the widgets.php manually, I discovered a double quotation mark ” was still there.

    If these comments do stay, a note to other readers… Either carefully type in two ‘ or just copy the master’s suggestion directly, and paste in :)

  5. admin on 05.11.2007 at 9:07 am | permalink
  6. @Chris: Good thing you managed to solve that. I’m going to add a note above to try and make it clearer, and also one warning people to backup their widgets.php file ;)

  7. Deaf Musician on 05.23.2007 at 12:55 am | permalink
  8. Why go through all that?!?!?? You can just find out the ID or class for that section’s title and hide it with CSS.

  9. shaz on 06.12.2007 at 12:34 am | permalink
  10. good tips nice blog (checking through all the nofollow blog community).

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>