Category Spacing

You see, under normal circumstances you would need the space to be appended automatically, saving you the trouble of adding this in your theme, each time you call a category listing function. However, there are cases (such as mine) where a space is unnecessary and, if you’re as nit-picky as I am, an eye-sore. There’s a way to fix it, though, so let’s get to it.

The function I use to list my categories is called the_category(). I use it in such a way that quotes (and commas) are wrapped around each category’s name. When there’s only one category, this isn’t a problem, but with multiple categories an extra, unneeded space is inserted. Here’s what my code looks like:


&#8220;<?php the_category('&#8221;, &#8220;') ?>&#8221;

As you can see, there are no extra spaces in my code, so the problem is coming from Wordpress itself. The file is located in your wp-includes/template_categories.php file. On line 78, you should find if (0 < $i) $thelist .= $separator . ' ';. Yep, that right there is the problem. Snip it out (so it looks like if (0 < $i) $thelist .= $separator;), and you're all set.

Hopefully this'll be useful for someone. It took me awhile to decide to do it, since I figured it'd be a hassle to get into the code, but it wasn't really that difficult to locate and destroy fix the problem.

July 15th, 2005 | No Remarks

Comments

  1. Mike Cherim Comments:

    I never noticed that here. Mine doesn’t do that. And since you fixed it, well, we can’t see an example :(

    Good fix, Jona.

  2. Jona Comments:

    Where the categories would be something like: Posted in “Category 1,” ” Category 2″, they now say: Posted in “Category 1,” “Category 2″ — notice the space before Category 2 in the first one.

  3. Julz Comments:

    Wow, I would have never noticed that. Ha, good job Jona!

  4. Jason Comments:

    I think that the strike tag was decapreated (spelling lol?). You should use the del tag.

    /off-topic

  5. Jona Comments:

    Thanks, nice catch, Jason.

Leave a Comment