WordPress the_tags() Function

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

Definition

In WordPress, the_tags() prints the tags of the current post as links. Each link goes to the page that lists all posts with that tag.

If the post has no tags, nothing is printed.

Syntax

A few ways to call the_tags().

WordPress
<?php
the_tags( 'Tags: ', ', ', '' );
CallWhat it does
the_tags()Print Tags: followed by the tag links, separated by commas.
the_tags( 'Topics: ', ' | ' )Use your own label and separator.
the_tags( '<p>Tags: ', ', ', '</p>' )Wrap the tags in a paragraph.
get_the_tag_list()Return the same HTML as a string.

It prints the tag list. The arguments are before, separator, after.

Full declaration
WordPress
the_tags( string $before = null, string $sep = ', ', string $after = '' ): void

Parameters

ParameterDescription
$beforestring. Text before the tags. Default is Tags:.
$sepstring. Text between tags. Default is ,.
$afterstring. Text after the tags. Default is empty.

Return Value

Return ValueDescription
voidNothing is returned. The links are printed, or nothing if the post has no tags.

WordPress Examples

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

Example 1 — Default tag list

Print the tags with the default settings.

WordPress
<?php the_tags(); ?>

How It Works

  1. The default label is Tags:.
  2. Each tag is a link to its tag archive.
  3. A comma and a space go between the tags.

Example 2 — Custom label and separator

Change the text around the tags.

WordPress
<?php the_tags( 'Topics: ', ' | ', '' ); ?>

How It Works

  1. The first argument is the label.
  2. The second argument is the separator.
  3. The third argument is empty, so nothing follows the tags.

Example 3 — Wrap in a paragraph

Use before and after to add HTML, only when tags exist.

WordPress
<?php the_tags( '<p class="tags">Tags: ', ', ', '</p>' ); ?>

How It Works

  1. The before and after text are printed only when the post has tags.
  2. This avoids empty paragraphs.
  3. You can add a class for styling.

Frequently Asked Questions

It prints the tags of the current post as links to the tag pages.
Before text, separator, and after text.
Nothing is printed, not even the before or after text.
Categories group posts in broad topics. Tags describe small details. Use the_category() for categories.
Use get_the_tag_list().

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.

11 people found this page helpful