Safe Title: a WordPress plugin

Friday, 17 June 2005

Here’s an amusing hack to fix a niggling problem in the WordPress default theme. I came up with this soon after I started using WordPress, but I recently noticed that this small annoyance had generated a discussion on Mathibus.com. My fully automatic solution is now ready for a waiting world.

When posting to your WordPress blog, sometimes you just want to use HTML in the title. You want to make some words stand out with color, or use italics or a code font. (Here’s an example of an HTML post title on this very website.)

Sadly, the default theme included with WordPress 1.5 can’t handle this; it fails to strip HTML tags from the title when it appears inside an HTML attribute, leading to deformed page titles. As an experiment, I wrote a plugin to solve this problem without requiring any changes to the default theme.

For full details and download, see the main Safe Title page.

Tags:

3 comments

You can leave a comment, or trackback from your own site.

  1. Nice, you made a plugin for it! However, output buffering sucks. Performing such heavy operations before sending out a page makes me wonder if it’s actually better to leave the HTML out of the title at all! Not to bash your plugin, not at all — it rawks! — but it’s just so silly WordPress hasn’t got this implemented. I hope the dev team soon applies my patch, so people won’t have to hack their way or use plugins in order to be able to embed HTML into post titles.

  2. Writing this plugin was a useful exercise for many reasons. I’ve discovered a few bugs in WordPress:

    1. “the_title” filters are called with varying argument. Sometimes called with just the title as argument, sometimes with a post object, and sometimes with the title and the before and after strings. Safe Title expects three args, so frequently doesn’t work properly because of this WordPress bug.

    2. In function next_post(), calls the “the_title” filters with a nonexistent $nextpost variable. It should be $post.

    Note to self: submit a patch to WordPress core.

  3. Testing. ????OK.

Leave a comment