← Back to blog

WordPress tags: what they are, how they differ from categories, and what deleting one actually does

The SandyWP team 10 min read

WordPress tags are optional, free-form labels you attach to posts to describe specific details, such as "PHP 8.3" or "WooCommerce", while categories group posts into a few broad sections. A post can have any number of tags or none, tags have no parent-child structure, and every tag gets its own archive page at /tag/<slug>/.

That covers what every guide covers. This post also explains where tags live in the database, what the count on the Tags screen leaves out, and what happens to your URLs when you delete, rename or merge a tag, because that is where tidying up goes wrong.

What are tags in WordPress?

A tag is a term in the built-in post_tag taxonomy. WordPress registers it in create_initial_taxonomies() with hierarchical set to false, attached to the post post type only, public, and exposed in the REST API under the base tags.

Each tag has a name, a slug and an optional description. The slug forms its URL: /tag/<slug>/ by default, or /<your-base>/<slug>/ if you set a Tag base under Settings, Permalinks.

Every tag archive also has a feed at /tag/<slug>/feed/. That is the whole feature: a label, an archive and a feed.

What is the difference between categories and tags in WordPress?

Both are taxonomies and both are stored the same way. The differences are in how WordPress treats them.

Categories Tags
Structure Hierarchical (parent and child) Flat
Required? Yes. A post with none gets the default category, "Uncategorized" on a new install No. Zero tags is fine
Can you delete them all? No. wp_delete_term() refuses to delete the default category Yes
Default URL /category/<slug>/ /tag/<slug>/
Template file category-<slug>.php, category.php tag-<slug>.php, tag-<id>.php, tag.php
Typical number A handful As many as you need

A useful rule: categories answer "which section of the site is this in?", tags answer "what specific things does this post mention?". If you would put it in a navigation menu, it is a category.

A category and a tag can share a name and a slug. wp_unique_term_slug() has allowed duplicate slugs across taxonomies since WordPress 4.1, so /category/news/ and /tag/news/ can both exist and point to different lists of posts.

That is legal, and also a good way to confuse readers and split your own internal links. Pick one.

Can you assign multiple tags to a WordPress post?

Yes. Core sets no limit on how many tags a post can have.

There are three places to add them:

  • The block editor. In the post's settings sidebar, open the Tags panel and type. The field's help text reads "Separate with commas or the Enter key." Typing a name that matches an existing tag reuses it; anything else creates a new tag.
  • Posts, Tags. Create tags in advance, edit names and slugs, and add descriptions. Some themes print the description at the top of the tag archive.
  • Bulk edit on the Posts screen. Select posts, choose Edit from Bulk actions, and type tags into the Tags box.

Bulk edit can only add tags. In bulk_edit_posts(), core merges the tags you type with each post's existing tags (array_merge( $current_terms, $new_terms )), so there is no way to remove a tag from fifty posts in one go from that screen.

To remove one tag from many posts, delete the tag itself, or use WP-CLI (see the cleanup section below).

Where are WordPress tags stored?

Three tables, all shared with categories and every other taxonomy:

  • wp_terms holds the name and slug.
  • wp_term_taxonomy says which taxonomy the term belongs to (post_tag), holds the description, and stores a cached count.
  • wp_term_relationships links each post ID to each term it carries.

You can see a post's tags straight from the database:

SELECT t.name, t.slug, tt.count
FROM wp_terms t
JOIN wp_term_taxonomy tt ON tt.term_id = t.term_id AND tt.taxonomy = 'post_tag'
JOIN wp_term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tr.object_id = 123;

Swap wp_ for your real table prefix. On a site where you have SSH and WP-CLI, wp db query runs it without phpMyAdmin.

What does the tag count on the Tags screen actually count?

Published posts only. That number is the cached count in wp_term_taxonomy, and _update_post_term_count() builds it by counting posts whose status is in a list that defaults to array( 'publish' ).

Drafts, scheduled posts, pending posts and private posts are not counted. A plugin can change the list through the update_post_term_count_statuses filter, but core never does.

This is the trap in every "delete your unused tags" tutorial. A tag showing 0 on the Tags screen may still be attached to a draft you are halfway through, or to a post scheduled for next Tuesday.

Delete it and that post loses the tag silently. Before you delete anything with a count of 0, check what is really using it:

wp db query "
SELECT t.slug, p.post_status, COUNT(*) AS posts
FROM wp_terms t
JOIN wp_term_taxonomy tt ON tt.term_id = t.term_id AND tt.taxonomy = 'post_tag'
JOIN wp_term_relationships tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN wp_posts p ON p.ID = tr.object_id
WHERE tt.count = 0
GROUP BY t.slug, p.post_status;"

Any row this returns is a tag that looks unused but is not. Tags that are truly unused do not appear at all, because they have no rows in wp_term_relationships.

If a count looks wrong for any reason, wp term recount post_tag rebuilds it.

What happens when you delete a tag in WordPress?

Three things, and only one of them is in the admin's confirmation dialog.

  1. The tag is gone for good. Terms have no trash. The REST API says so in its own error message: "Terms do not support trashing." There is no undo short of a database backup.
  2. Posts keep everything else. wp_delete_term() removes the tag's rows from wp_term_relationships and leaves the posts alone. Tags have no default term, so nothing replaces the deleted one.
  3. The tag's URL starts returning 404. Nothing redirects it.

The third point surprises people because posts behave differently. When you change a post's slug, WordPress stores the old one in _wp_old_slug and wp_old_slug_redirect() sends visitors to the new URL.

That function only looks up posts. Terms have no equivalent, so renaming a tag's slug or deleting a tag breaks every link to its archive, including links from other sites and from your own old posts.

If a tag archive has inbound links worth keeping, add a 301 redirect before you delete or rename it, with your redirect plugin or the server config.

Where do tags show up that you might not expect?

The REST API lists every tag, used or not. /wp-json/wp/v2/tags is public on any site with the REST API enabled, and its hide_empty parameter defaults to false.

That includes tags with a count of 0, so a tag you added only to an unpublished draft is visible to anyone:

curl -s 'https://example.com/wp-json/wp/v2/tags?per_page=100&_fields=name,slug,count'

If you tag drafts with a client name or a launch codename, that name is public before the post is. Use a private note or a custom field for that, not a tag.

An empty tag archive is a 200, not a 404. WP::handle_404() deliberately skips the 404 for a tag, category or taxonomy archive when the term exists, even with no posts in it.

So /tag/<slug>/ for a tag with only draft posts serves a "nothing found" page with a 200 status. The core sitemap is stricter: /wp-sitemap-taxonomies-post_tag-1.xml queries with hide_empty set to true and lists only tags that have published posts.

The Tag Cloud shows the 45 most-used tags. Both wp_tag_cloud() and the Tag Cloud block default to 45 tags, chosen by count and then sorted by name, sized between 8pt and 22pt.

The block's numberOfTags attribute allows 1 to 100, so a guide quoting a different cap is out of date.

In a classic theme it is also available as a widget (where widgets went in block themes explains the difference).

Do WordPress tags help SEO?

Not directly. A tag is a label and an archive page, and the archive page is what a search engine sees.

That page is useful when a tag has enough posts to be worth landing on, such as a tag for a product name on a changelog blog. It is thin when a tag has one or two posts, and a site with hundreds of one-post tags has hundreds of near-empty pages that mostly repeat each other.

Two honest options, depending on how you use tags:

  • Use few, reused tags and let their archives be indexed. Write a description for the ones that matter.
  • Use tags freely for navigation and set tag archives to noindex in your SEO plugin. Noindex keeps them out of results; it does not stop them being crawled, and it does not remove them from the REST API.

Either way, robots.txt is not the tool for this: since WordPress 5.3 even core's own "discourage search engines" setting uses a noindex meta tag instead. Our robots.txt post covers how that works.

Can pages have tags in WordPress?

Not by default. post_tag is registered for posts only, which is why the Tags panel does not appear when you edit a page.

You can attach it to pages with register_taxonomy_for_object_type(). That alone has a catch: tag archives still list posts only, because when a tag archive has no post_type set, WP_Query falls back to post.

Both halves together, as a must-use plugin:

<?php
// wp-content/mu-plugins/page-tags.php
add_action( 'init', function () {
    register_taxonomy_for_object_type( 'post_tag', 'page' );
} );

add_action( 'pre_get_posts', function ( $query ) {
    if ( ! is_admin() && $query->is_main_query() && $query->is_tag() ) {
        $query->set( 'post_type', array( 'post', 'page' ) );
    }
} );

The same applies to a custom post type: add post_tag to its taxonomies argument, then include it in the tag archive query.

How to clean up, merge or convert tags without breaking things

Tag cleanup is a bulk, irreversible database change with public URLs attached. That is exactly the kind of job to run on a copy first, check the result, and only then repeat on production.

With SandyWP, the Cloner reads your live site and copies its database, themes, plugins and media into a disposable sandbox; production is never written to. You get SSH and WP-CLI on the copy, so the commands below run as-is.

List every tag with its count:

wp term list post_tag --fields=term_id,name,slug,count

Merge one tag into another. Core has no merge button. Add the new tag to every post carrying the old one, including unpublished posts, then delete the old tag:

OLD=wp-tips
NEW=wordpress-tips
for id in $(wp post list --tag=$OLD --post_status=any --format=ids); do
  wp post term add $id post_tag $NEW
done
wp term delete post_tag $OLD --by=slug

wp post term add takes slugs, so create the destination tag first if it does not exist (wp term create post_tag "WordPress tips" --slug=wordpress-tips). Then redirect /tag/wp-tips/ to /tag/wordpress-tips/.

Convert a tag into a category, or back. WP-CLI does it in one command, keeping the posts attached:

wp term migrate wp-tips --by=slug --from=post_tag --to=category

The documented output ends with "Success: Migrated the term ... for 1 post." The URL changes from /tag/ to /category/, so this also needs a redirect.

The other route is the Categories and Tags Converter listed under Tools, Import. Its wordpress.org page shows version 0.6.3, last updated October 2024 and tested up to 6.7, with a warning that it has not been tested with the latest three major releases.

WP-CLI is the safer path on a current site.

After any of these, check three things on the copy before touching production: the Tags screen counts, a handful of posts you know were affected (including a draft), and the old tag URLs, which should now redirect rather than 404.

The short version

  • Tags are flat, optional labels for posts; categories are required, hierarchical sections.
  • The count on the Tags screen is published posts only. A 0 can still mean "used by a draft".
  • Deleting a tag is permanent and its URL 404s with no redirect. Renaming the slug does the same.
  • /wp-json/wp/v2/tags lists every tag, including ones only on drafts.
  • Pages need register_taxonomy_for_object_type() and a pre_get_posts change to appear in tag archives.
  • Merge, convert and delete tags on a clone of the site first, then add redirects on production.