widow

Solving the widow problem on your Drupal website

Posted by andu
Sun, 2007-08-05 12:21

What is the widow problem you might ask?

in typesetting, a widow is a single word on a line by itself at the end of a paragraph and is considered bad style.
widow description

From Shaun Inman.

I'm going to present two methods of avoiding the widow problem on your website, each with it's own advantages and disadvantages.

  1. The client side approach

    Using Javascript we can manipulate the headings after the page has loaded and add a non breaking space between the last two words of the content. There's a jQuery plugin which does this. I modified it to solve some bugs and created a module which uses it. It applies the transformations to elements which match one of the following rules:

    • #content h1.title
    • #content h2.node-title a

    It's available here: http://drupal.org/project/widont

    Advantages: easy to install, most of the time works out of the box.

    Disadvantages: it doesn't work when Javascript is disabled, on some themes who use different classes for the title headings it will fail.

  2. The server side approach

    You'll need to know how to edit the files from the theme you're using. I'm going to assume that you're using Garland, the default Drupal theme, but the instructions can be applied to every Drupal theme out there.