Monday August 31, 2009 at 19:52

A stupid wp-caption width issue

Or: “How I learned to stop CSSing and get my hands dirty with some PHP”

From Wordpress, wp-includes/media.php, line 596:

return '<div ' . $id . 'class="wp-caption ' . $align . '" style="width: ' . (10 + (int) $width) . 'px">'

A deceptively simple line of code. This constructs the basic caption box around an image in a Wordpress post/page.

This line also wasted a good hour or two of my time today. Why? The last half is to blame.

 (10 + (int) $width) . 'px">'

That simple bit of PHP adds 10 pixels to the width of the caption div. Spoiler alert: This drove me batshit insane. No matter what I told the CSS to do, no matter how much negative margin I put on the div, it was always 10 pixels wider than it should have been. After a quick jaunt through the source code (And Coda’s awesome Search in Open Files feature, I located this line and set that 10 to a zero. Problem solved.

What annoys me is that it was there in the first place. What possible use could that extra 10 pixels serve? Is it an IE fix? (God I hope not). Is it a mistake? Or could it even be part of a massive conspiracy to annoy me?

I would also like to point out that this line is in Wordpress’ core, where no theme or plugin can go*. Absolutely disgusting.

We may never know, but this only serves to reinforce my point that WORDPRESS SUCKS. Had I been thinking at the time, I would have told my client to go with Tumblr instead.

The most disappointing thing here is that Wordpress has a huge community that has produced a staggering number of themes and plugins that do everything you want and more, but the post editor and source code are so sub-par. Ah well.

*As far as I know.

Comments (View)
blog comments powered by Disqus