How to remove link from the_category in Wordpress
Recently I’ve been delving into customising both Wordpress and Drupal and although I’d consider myself still a beginner, I still think it’s worth writing about problems I’ve encountered so others learning Wordpress & Drupal customisation, can do it without the same frustrations.
So today I’m going to talk about how I needed to include a post category on a post page. A client required each post to have a header above the post with the posts category name nicely styled with CSS above the post. After a read though the Wordpress documentation and some experimentation, I ended up with the the_category tag and what I thought would be the solution to my problem.
Unfortunately, this wasn’t entirely correct as the_category tag causes the category name to be a link text as well which wasn’t what I wanted. So I dugg around the Wordpress docs and forums to try to find how this could be done. It wasn’t long before I found others looking for the same solution and responded to their own problem post with… ‘it’s ok, I’ve worked it out’. That’s right… they didn’t put how they solved the problem which is why I couldn’t resist writing about this. So here is the solution…
Instead of using the_category, you use get_the_category as follows
<?php
foreach((get_the_category()) as $category) {
echo $category->cat_name . ' ';
}
?>
get_the_category tag comes with other objects that are available from the array.
- cat_ID - category id
- cat_name - category name
- category_nicename -post slug
- category_description - category description
- category_parent - the current categories parent category id
- category_count - the number of uses of this category
You can find more information at the url below.

July 17th, 2008 at 6:01 am
THANKS A LOOOOOOOOOOOOOOOOOOOOOOTTTT!!!! I mean THANKS!! Really! It would be great to know how to modify the php functions to have them behave any way I wanted, but I don’t know squat of php