WordPress the_category() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints category links

Definition

In WordPress, the_category() prints the categories of a post as links. Each link goes to the page that lists all posts in that category.

Use it inside The Loop, for example under the post title.

Syntax

A few ways to call the_category().

WordPress
<?php
the_category( ', ' );
CallWhat it does
the_category()Print the categories as a list.
the_category( ', ' )Print the categories separated by a comma.
the_category( ' | ', 'multiple' )Show parent categories with their children.
get_the_category_list( ", " )Return the same HTML as a string.

It prints the links. If you pass no separator, the categories are printed as an unordered list.

Full declaration
WordPress
the_category( string $separator = '', string $parents = '', int|false $post_id = false ): void

Parameters

ParameterDescription
$separatorstring. Text between categories. Default is empty, which makes a list.
$parentsstring. How to show parent categories: multiple, single, or empty. Default is empty.
$post_idint|false. The post ID. Default is false, which uses the current post.

Return Value

Return ValueDescription
voidNothing is returned. The links are printed.

WordPress Examples

Three short examples. Each one shows the code and what it prints.

Example 1 — Inline category list

Print categories separated by commas.

WordPress
<p>Posted in: <?php the_category( ', ' ); ?></p>

How It Works

  1. The separator ', ' goes between links.
  2. Each link goes to a category archive.
  3. The rel="category tag" is added by WordPress.

Example 2 — Default list

With no separator you get an unordered list.

WordPress
<?php the_category(); ?>

How It Works

  1. No separator means a list.
  2. Each category is one li.
  3. You can style .post-categories in CSS.

Example 3 — Categories of another post

Pass a post ID as the third argument.

WordPress
<?php the_category( ' / ', '', 42 ); ?>

How It Works

  1. The second argument is empty, so there is no parent display.
  2. The third argument 42 is the post ID.
  3. The separator is /.

Frequently Asked Questions

It prints the categories of a post as links to their archive pages.
Pass a separator, for example the_category( ', ' ).
With no separator, the_category() prints an unordered list.
Use get_the_category_list() for HTML, or get_the_category() for an array of category objects.
Use the_tags().

Browse all post functions

Open the functions index for simple guides with examples and FAQs.

Post Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful