Fixed WordPress calendar title formatting issue ($ak_title_separator) in cached pages

By Richard X. Thripp at 2008-08-20T02:41:27Z in News, with these tags: blogs, bugs, caching, calendar, posts, sidebar, widgets, jump to comment form. 371 words.

I discovered an annoying issue with the calendar widget on my Thripp.com blog today. I use the widget which is included in WordPress, WordPress MU, and Thripp.com, but for the Internet Explorer, Safari, and Camino browsers, it formats the pop-up titles with line breaks instead of commas. In Firefox it looks like this:

WordPress Calendar, Firefox

It’s pretty reasonable to use commas to separate post titles. But in Internet Explorer, WordPress generates the page using line breaks instead:

WordPress Calendar, Internet Explorer

That makes sense, since Firefox can’t handle line breaks in title tags. Unfortunately, as you may know, I use WP Super Cache. If the first visitor to a page is using Internet Explorer, his hit generates the cached copy. For later visitors in Firefox, the titles then look like this:

WordPress Calendar, bad version (IE in Firefox)

Bad bad bad. There’s no space or comma or line break or anything. It’s illegible.

The solution is to serve the same formatting to all browsers, so caching is a non-issue. I don’t care for the line breaks anyway; everything should have commas. I found the culprit in wp-includes/general-template.php. This is in WordPress MU 1.5.1, but it’s the same in WordPress 2.5.1 and the new 2.6 series:

if (strpos($_SERVER['HTTP_USER_AGENT'], ‘MSIE’) !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), ‘camino’) !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), ’safari’) !== false)
$ak_title_separator = “\n”;
else
$ak_title_separator = ‘, ‘;

Change that to this:

$ak_title_separator = ‘, ‘;

Simple. I’m surprised no one else is talking about it. I guess I’m the only one who is annoyed enough.

If you want the best of both worlds, use this instead:

$ak_title_separator = ‘, \n’;

It’ll look right in Firefox and the same as before in Internet Explorer (line breaks), except with a comma after each title but before the line break.

The problem with this is that I’m hacking the core files, so I’ll have to re-apply the updates by hand when I upgrade WordPress MU. Thripp.com is on 1.5.1 now (2.5.1 in regular WP), but I’m skipping 2.6 to wait for 2.7 for Thripp.com. Hopefully the developers will have more bugs worked out, with new ones to go along. :cool:

Surely there’s some way to do this with a plugin outside the core, but since it’s such a small thing I’m not going to look.

Your Thripp.com calendar widgets can now look nice for everyone. You can add one under Design > Widgets.




Have no fear — commenting is here. Comments RSS feed.

These HTML tags work: a href, abbr, acronym, b, blockquote, code, em, i, strike, strong, u. You will be emailed if anyone replies to your comment. Gravatars work here. Thanks for commenting!