Support » Fixing WordPress » strtolower (?)

  • Quick php question:

    Trying to get my categories to print in lowercase in one instance. I’ve tried hacking strtolower() to this line of code in the theme templates:

    <?php the_category(', ') ?>

    but can’t get it to work. And I’m not sure if this is the right function to be using.

    Any php gurus out there know the answer? If strtolower() will work, how would this look codewise with the above WP php call for the category? Unfortunately, CSS is not going to cut it as I need cats to be low caps even without styles enabled.


Viewing 3 replies - 1 through 3 (of 3 total)
  • skippy



    the_category() sends the name of the category directly to the browser, so you won’t be able to use strtolower on it.

    You could try using get_the_category(), which will return to you an array of category objects. Then you could echo strtolower(...); each category name as needed.

    Thanks Skippy. I needed this to impact all categories so I went back to the source of the_category(). Here’s what I did:

    I fixed it by hacking the templates-function-category.php file. If you capitalize your categories normally, but want them lowercase only on posts like me (mainly for tags) add this line to the file:

    $category->cat_name = strtolower($category->cat_name);

    Around line 75 where you see these lines of code (hack is in bold):

    foreach ($categories as $category) {
    $category->cat_name = $category->cat_name;

    $category->cat_name = strtolower($category->cat_name);
    if (0 < $i) $thelist .= $separator . ' ';

    If this breaks something, I’ll post it back here. I checked it and so far everything seems ok. Hope this helps someone.




    I generally discourage people from modifying the core WordPress files, as thet complicates upgrades.

    I’m glad you were able to fix this for yourself.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘strtolower (?)’ is closed to new replies.