WordPress Post’s Category Name without capitalisation

I am using the following piece of code in wordpress to retrieve the name of the categorys however it is capitalising the category names.

<?php foreach ($categories as $category):?>
        <button data-filter=".<?php echo $category->name;?>">Button</button>
<?php endforeach; ?>

The output I am getting is be this

Read More
<button data-filter=".Category">Button</button>

But I need it to output as

<button data-filter=".category">Button</button>

Thanks and hopefully I find a solution.

Related posts

Leave a Reply

1 comment

  1. This should work:

    <?php foreach ($categories as $category):?>
        <button data-filter=".<?php echo strtolower($category->name);?>">Button</button>
    <?php endforeach; ?>
    

    strtolower() is a php function that

    Returns string with all alphabetic characters converted to lowercase.