• At present the wp_list_categories() function returns li as follows:

    <li class=”cat-item cat-item-11″>

    I want to amend the function so that that I can apply catergory specific styles using the slug name instead of ‘cat-item-11’. So something like this:

    <li class=”cat-item cat-item-11 slug-name“>

    Is it possible to amend the wp_list_categories() to do this?

    Any help much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Doing this cleanly would be surprisingly difficult.

    Instead, can you just style based on the cat IDs instead of the slugs? For example, You know that the “Uncategorized” category will have the class “cat-item-1”.

    Are you just trying to make the stylesheet more readable, or are you concerned that cat IDs will shift?

    Thread Starter r4z4

    (@r4z4)

    I can apply the styles on the cat IDs instead. I was just wondering if there was a way to use the slugs because I will know them as and when I create any future categories and could then code the stylesheet without having to check the cat ID value first.

    Thanks for the response 🙂

    Just add comments to css like this: /* id 1 — uncategorized */, etc.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Amending wp_list_categories() to return slug name in the <li> class?’ is closed to new replies.