I want to display category's slug as a class.
I try to code and put this into functions.php
add_filter('the_category', 'my_custom_get_the_category_list');
function my_custom__get_the_category_list($thelist, $post_id = false ) {
global $wp_rewrite;
$categories = get_the_category( $post_id );
foreach ( $categories as $category ) {
$thelist = str_replace('rel="', 'class="category-'.$category->category_nicename.'" rel="', $thelist);
}
return $thelist;
}
But there is something wrong. I use get_the_category_list() in category.php
Then every category displays the same class.
<ul class="post-categories">
<li><a href="http://localhost/test_blog/topics/editorial" title="View all posts in Editorial" class="category-editorial" rel="category tag">Editorial</a></li>
<li><a href="http://localhost/test_blog/topics/economy/business" title="View all posts in Business" class="category-editorial" rel="category tag">Business</a></li>
<li><a href="http://localhost/test_blog/topics/economy/national" title="View all posts in National" class="category-editorial" rel="category tag">National</a></li>
</ul>
Where did I do wrong?