Change how the categories are listed for posts

Most themes have a link to each category in underneath the title of the post on the individual posts.

These links are rarely if ever, styled, and in most cases push “link-juice” toward the category page.

This is not good for SEO, so the best solution is to change the way the categories for the post is displayed.

[warning]

You will have to edit your theme for this, so this is not for beginners.

[/warning]

1. Find and locate your “single.php” file in your theme.

2. Find the following code

<?php the_category(', ') ?>

Now, there are several ways to change it. The first solution is to simply list the categories without having any links to them. That can be done by replacing above code with the following:

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

This just lists all categories as a long line.

The second solution is to list the categories as you usually would, but by adding rel=”nofollow” to the links, so you do not pass link-juice to the category pages.

This can be done with the following code:

<?php
$catcount=0;
foreach((get_the_category()) as $category) {
$catcount++;
if ($catcount>1) {echo ', '; }
echo '<a href='.get_category_link($category->cat_ID).' rel='nofollow category tag'>' . $category->cat_name. '</a>';

}
?>

The $catcount variable is a little code I added which displays a comma if there are more than one category. If we did not check for this, the code would simply add a comma every time, even if there was just one category listed.

Read also  How To Delete Duplicate Posts in WordPress

If you want to use something else such as “and”  instead of the ,”” comma, change the following line:

if ($catcount<1) {echo ', '; }

Example:

if ($catcount>1) {echo 'and '; }

If you are looking for other tips and tricks, check out Setting Featured Image via code or WordPress Multisite Search.

Popular searches to this page
  • post categories

1 thought on “Change how the categories are listed for posts”

Leave a Comment

Your email address will not be published. Required fields are marked *

Free eBook - 

Guide to success with SEO

Join the newsletter for more interesting articles, discount code for SEO Booster Pro and much more.

Guide to success

with SEO 2018

FREE

We respect your privacy and do not share your details with others

Join our newsletter and get a free eBook, interesting articles, discount codes and much more.