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.

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

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.

SEE ALSO:  Autologin a WordPress user in your PHP script

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.

Subscribe

HTTP Error 404 and SEO: What You Need to Know

You've seen it in your own personal web browsing, the HTTP error 404. you click on a promising link but are disappointed to encounter an error screen. If this frustrates you, how do you think your users feel when they encounter it on your website? It certainly affects...

SEE ALSO:  number_format_i18n Function Reference and Usage

How to submit a sitemap to Google

You can't succeed on the web if Google doesn't know about your site. Learn how to submit a sitemap to Google. It's the biggest search engine out there with over 3.5 billion searches daily. People rely on it to bring them everything from movie schedules to explanations...

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match