Skip to content

Everything for WordPress, web development — and beyond

🔖 How to enable tags on WordPress pages

🔖 How to enable tags on WordPress pages

WordPress pages don't support tags out of the box, and this is annoying right up until you understand why it's done that way. A page in WordPress is technically a custom post type to which the post_tag taxonomy simply isn't attached. Core developers kept tags only for posts, treating pages as static content.

But in practice this limitation can be bypassed in five minutes. Two methods: a line of code in functions.php or a micro-plugin that you can enable and disable without editing your theme. Below are both options with an explanation of what exactly happens under the hood.

💡 Quick overview:

  • Register the post_tag taxonomy for the page post type using a single function register_taxonomy_for_object_type

  • Add tag support to archives via the pre_get_posts hook so pages appear in tag query results

  • The code works for any custom post types; just repeat the call with the desired type name

  • Everything wraps into a separate plugin in one minute: file → plugin header → code → activation

Why tags on pages

Tags aren't just a sidebar cloud. They're a navigational axis that links scattered pages into thematic groups faster than categories or menus.

WordPress pages often proliferate: contacts, policies, terms, service landing pages, portfolios, documentation. Without tags the connection between them relies solely on manual links in the text. With tags, a single "Shipping" page automatically ends up in the "logistics" group next to the "Returns" page, and visitors click the tag to see everything related.

For SEO, tags on pages provide additional internal linking and reduce bounce rates: users don't leave after the first page but dive into a thematic collection. Plus tags get into the sitemap, helping search engines better understand the structure.

Method 1: code in functions.php

The most direct route is adding a snippet to the functions.php file of your active theme. Open wp-content/themes/YOUR_THEME/functions.php and paste the code before the closing ?> or at the very end of the file:

1/**
2 * Add tag support to WordPress pages.
3 * Code — in functions.php of child theme or via Code Snippets plugin.
4 */
5function sdstudio_add_tags_to_pages() {
6 register_taxonomy_for_object_type( 'post_tag', 'page' );
7}
8add_action( 'init', 'sdstudio_add_tags_to_pages' );
9
10/**
11 * Include pages in tag archive queries.
12 * Without this, pages won't appear on /tag/tag-name/
13 */
14function sdstudio_pages_in_tag_archives( $wp_query ) {
15 if ( $wp_query->get( 'tag' ) ) {
16 $wp_query->set( 'post_type', 'any' );
17 }
18}
19add_action( 'pre_get_posts', 'sdstudio_pages_in_tag_archives' );

Here's what's happening. The function register_taxonomy_for_object_type() links the existing post_tag taxonomy to the page post type. This is a core WordPress function; documentation on developer.wordpress.org. It doesn't create a new taxonomy but only adds the "pages → tags" relationship.

The pre_get_posts hook modifies the SQL query before it executes. When WordPress builds a tag archive page (/tag/name/), it searches only for posts of type post by default. The line $wp_query->set( 'post_type', 'any' ) expands the selection to all types: pages, posts, custom types.

After inserting the code, go to any page and a "Tags" block will appear in the sidebar just like in regular posts. It works immediately; no need to clear the cache.

Adapting for custom post types

If you have custom post types (CPT) such as portfolios, testimonials, or products that also need tags, add the same number of register_taxonomy_for_object_type() calls inside your init function:

1register_taxonomy_for_object_type( 'post_tag', 'portfolio' );
2register_taxonomy_for_object_type( 'post_tag', 'testimonials' );

The CPT name is the second argument, the same one specified when registering the type via register_post_type(). No additional edits to pre_get_posts are needed: 'any' already includes all registered types.

Method 2: a separate plugin

Editing functions.php directly is a working solution, but fragile. Switch themes and the code disappears, taking tags off pages with it. For those who manage multiple sites or frequently change themes, it's more reliable to move the snippet into a separate plugin.

Create the file wp-content/plugins/sdstudio-tags-for-pages.php with this content:

1<?php
2/**
3 * Plugin Name: Tags for Pages
4 * Description: Enables post tags on WordPress pages and custom post types
5 * Version: 1.0
6 * Author: SDStudio
7 * License: GPL-2.0+
8 */
9
10// Direct access — forbidden
11if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13}
14
15// Tags → pages
16function sdstudio_tags_for_pages() {
17 register_taxonomy_for_object_type( 'post_tag', 'page' );
18}
19add_action( 'init', 'sdstudio_tags_for_pages' );
20
21// Pages → tag archive
22function sdstudio_pages_in_tag_queries( $wp_query ) {
23 if ( ! is_admin() && $wp_query->is_main_query() && $wp_query->get( 'tag' ) ) {
24 $wp_query->set( 'post_type', 'any' );
25 }
26}
27add_action( 'pre_get_posts', 'sdstudio_pages_in_tag_queries' );

The difference from the first method is the check ! is_admin() && $wp_query->is_main_query(). It ensures that admin queries aren't affected: pre_get_posts fires everywhere, including the page list in the dashboard, and without this check you can get unexpected admin behavior when filtering.

The file is ready; go to Plugins, find "Tags for Pages" and activate it. That's it. When you switch themes the plugin stays active and tags don't disappear. On multisite the plugin can be enabled per site or network-activated for the entire network.

Method 3: ready-made plugins from the directory

If you don't want to write code, ready-made solutions from WordPress.org handle the task. They add not only tags but also categories for pages, plus a management interface.

Add Categories to Pages is a lightweight plugin that enables both categories and tags for pages with a single checkbox. No settings, no ads. Suitable when you just need things to work without extra screens.

Here's a video demonstration of adding tags to pages via code and via plugin, 4 minutes, all steps shown in real time:

Key point: third-party plugins bring additional code and hooks. If your site is already loaded with a dozen plugins, one more is one more point of failure. The code from methods 1 and 2 weighs mere bytes and doesn't add database queries beyond the standard ones.

⁉️🤔 Frequently asked questions

Does this work on multisite? Yes, the code is universal. You can activate the plugin per site or enable it network-wide via "Network Activate."

On WordPress multisite the code works identically on all sites in the network. The function register_taxonomy_for_object_type() is bound to the post_tag taxonomy, which exists separately on each site in the network, so tags don't overlap between sites. For each child site, tags on pages are enabled independently: activate the plugin on one site and tags appear only there.

Do I need to update permalinks after inserting the code? No, the URL structure doesn't change. Tags on pages don't add new rewrite rules.

WordPress stores the "page, tag" relationship in the wp_term_relationships table, the same one used for posts. No rewrite rules are affected: the tag archive already exists (/tag/name/), and pre_get_posts simply includes pages in its query. No need to touch permalinks; everything works immediately after activating the code.

Will tags disappear when switching themes? It depends on the method. Code in the theme's functions.php will cause them to disappear. Code in a plugin or Code Snippets will preserve them.

When switching themes WordPress loads a new functions.php, so the snippet from the old theme stops executing and the tag metabox on pages disappears. The "page, tag" relationships in the database are not deleted though. Just restore the code (in the new theme or via plugin) and all previously assigned tags reappear in the admin.

Can I assign tags programmatically when importing pages? Yes, via wp_set_object_terms( $page_id, array( 'tag1', 'tag2' ), 'post_tag' ).

The function wp_set_object_terms() accepts a page ID, an array of tag names, and the taxonomy name. If a tag with that name doesn't exist, WordPress will create it automatically. This is convenient during migration: a script loops through all pages and assigns tags from a CSV file or an old CMS. It's important to run the script after init, otherwise the taxonomy isn't registered yet.

What about the tag cloud: will pages appear in it? Yes, the standard "Tag Cloud" widget will pick up tags from pages without additional configuration.

The wp_tag_cloud() widget collects all objects of the post_tag taxonomy by default, regardless of post type. As soon as a page has at least one tag, it enters the cloud on equal footing with post tags. Frequency is also calculated correctly: a tag on three pages and two posts yields a weight of "5" and displays larger.

What to choose: code or plugin

The specific choice depends on your scenario, not on a "right answer."

Single-site owners who don't change themes for years will find a snippet in functions.php sufficient: copy, paste, done. Freelancers with a dozen client sites find a plugin more convenient: send the zip file to the client or activate on a new project in seconds. Those already using Code Snippets or WPCodeBox can simply add the snippet to their collection; it won't be lost on theme updates and doesn't require a separate plugin.

If you need more than tags (categories, custom taxonomies, advanced filtering), look at ready-made plugins from WordPress.org. But for the task of "enabling tags on pages," seven lines of code are enough. Everything else is overkill.

Next, set up your tag structure: think through 5-7 key topics for pages and assign them. In a month the tag cloud will show which site topics are most strongly connected.