How to get this only in small letters (lowercase)?

The question:

I used the following code to give out the category name (without link) in a single post.

How would it be possible for the category name that is given out to only appears in small letters ?

I just think this has to be made with substring, but I dont get it 🙂
Could somebody please help me 🙂

<?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?>

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

I would personally achieve this by using strtolower which changes the case of the string.

    $categories = get_the_category();

    foreach($categories as $category)
        echo strtolower($category->cat_name) . ' ';

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment