Sign in to unlock all code snippets and resources
100% tested and verified code snippets
New here? Register for free to get started
© Copyright – 2025 – All Rights Reserved. Created by SuperWP
WordPress Posts come with built-in categories and tags, powerful tools for organizing and relating content. But what about Pages? By default, Pages are typically seen as standalone, static pieces of content, lacking this flexible classification system. While the Parent/Child page structure offers some hierarchy, it doesn’t provide the same level of organization or discoverability that taxonomies like categories and tags do.
What if you need to categorize your “About Us” pages by department, tag your “Resource” pages by topic, or filter a list of “Project” pages by client type? The default WordPress setup makes this challenging.
Fortunately, WordPress is incredibly flexible. With a bit of custom code, you can easily add categories and tags – custom taxonomies – to your Pages, bringing them the same organizational power as Posts.
In this guide, we’ll walk through the code for a simple custom WordPress plugin that does exactly that. It not only adds “Page Categories” and “Page Tags” to your edit screen but also enhances the WordPress admin area with filters, clickable terms, and sortable columns for your new taxonomies, and even displays the terms on the front end of your pages.
Let’s break down how this functionality is built.
The first step in adding categories and tags to pages (or any custom post type) is to formally introduce these new classification systems to WordPress. This is done using the powerful register_taxonomy()
function.
Our code defines two distinct taxonomies:
'hierarchical' => true
. This means Page Categories can have parent-child relationships, much like standard Post Categories. You can create nested structures if needed.'hierarchical' => false
. Similar to standard Post Tags, these are more freeform and don’t have a built-in hierarchy.We explicitly link these new taxonomies to the 'page'
post type using the second argument in register_taxonomy()
. Several other arguments are crucial: setting the user-friendly label
(what appears in the admin), making them public
and show_ui
so they are accessible and visible in the WordPress admin interface, enabling show_in_rest
for compatibility with the block editor (Gutenberg), defining a rewrite
slug for friendly URLs (e.g., /page-category/news/
), and crucially, setting show_admin_column
to true
to automatically add columns for these taxonomies on the Pages list screen.
This registration process needs to happen early in the WordPress loading process, which is why the function is hooked into the 'init'
action.
Once the taxonomies are registered, the code focuses on improving the user experience within the WordPress admin panel, specifically on the “All Pages” screen.
Adding Filter Dropdowns:
Navigating through many pages can be cumbersome. The code adds handy dropdown filters above the Pages list, allowing you to quickly narrow down the pages displayed based on their assigned categories or tags. This is achieved by hooking into 'restrict_manage_posts'
. Within this function, we check if we are on the ‘page’ post type screen, then retrieve all existing terms for ‘Page Categories’ and ‘Page Tags’ and generate the necessary HTML <select>
and <option>
elements to create the dropdown menus. When a user selects a term and clicks ‘Filter’, WordPress adds parameters to the URL (e.g., ?post_type=page&page_category=news
).
Implementing the Admin Filters:
Adding the dropdowns is only half the battle; the filter actually needs to do something. The code uses the 'pre_get_posts'
action hook. This powerful hook allows us to modify the main WordPress query before it runs. Inside the function hooked to 'pre_get_posts'
, we perform crucial checks to ensure we only modify the main query on the admin ‘edit.php’ page specifically for the ‘page’ post type. If a taxonomy filter is present in the URL (checked via $_GET
), we add a tax_query
parameter to the main query. The tax_query
tells WordPress to retrieve only pages that are associated with the selected term’s slug in the specified taxonomy.
Making Admin Column Terms Clickable:
Looking at the Pages list, you’ll see the ‘Page Categories’ and ‘Page Tags’ columns automatically thanks to show_admin_column => true
during registration. Our code enhances this further by making the terms listed in these columns clickable. Clicking a term here acts as a shortcut to apply the filter for that specific term, just like using the dropdown. This is done by filtering the content of the custom columns using the 'manage_page_custom_column'
hook. The code retrieves the terms for the current page, then loops through them, generating an HTML link for each term that points back to the edit.php
page with the filtering parameters set.
Making Columns Sortable & Handling the Sorting:
For even better admin management, the code makes the ‘Page Categories’ and ‘Page Tags’ columns sortable. This allows administrators to click the column headers to reorder the pages based on their taxonomy terms. The 'manage_edit-page_sortable_columns'
filter is used to tell WordPress that these columns are sortable.
Similar to filtering, the actual sorting logic is handled by hooking into 'pre_get_posts'
again. When a user clicks a sortable taxonomy column header, WordPress adds an orderby
parameter to the URL. Our function checks for this parameter. While directly sorting by taxonomy isn’t a default simple query parameter, a common approach is to modify the query to include a tax_query
for all terms in that taxonomy and then set the orderby
to 'name'
(the term name). This effectively sorts the pages based on their associated terms within that taxonomy context, providing a functional sort in the admin list.
Organizing content in the admin is great, but users visiting your site might also benefit from seeing the categories and tags assigned to a page. The code includes a basic implementation to display these terms on the front end.
By hooking a function to the 'the_content'
filter, the code automatically appends the list of assigned ‘Page Categories’ and ‘Page Tags’ after the main content of the page. It uses get_the_term_list()
to fetch and format the terms with links to their respective archive pages (e.g., /page-category/news/
).
While this simple method works, for more control over the exact placement and styling of the terms on your page, you would typically modify your theme’s page template files (page.php
, single.php
, or relevant template parts) to include the term display function (display_page_terms()
) exactly where you want it.
To implement this functionality on your WordPress site, you have a couple of options:
Method 1: Create a Simple Plugin Manually
wp-content/plugins/
directory. You could name it page-taxonomies
.page-taxonomies.php
./** Plugin Name: ... */
) are at the very top.Method 2: Use a Code Snippet Plugin
If you already use or prefer not to create separate plugin files for small code additions, you can use a popular code snippet plugin like “Code Snippets”.
Both methods achieve the same result. Using a code snippet plugin can be convenient for managing multiple small code additions in one place, while creating a dedicated plugin file is a standard practice for more substantial functionality.
Once activated using either method, you will see “Page Categories” and “Page Tags” sections when editing pages, and the columns, filters, and sorting options will appear on the “All Pages” list screen. The terms will also show on the front end of your pages (appended to the content).
This code provides a solid foundation. You can easily customize it further:
display_page_terms
or integrating it directly into your theme templates.Adding custom taxonomies like categories and tags to your WordPress Pages significantly enhances their organizational potential, making your content more manageable in the admin and potentially more discoverable for your visitors. By understanding the key WordPress hooks and functions used in this plugin code – from registering the taxonomy to modifying admin lists and front-end display – you gain valuable insight into extending WordPress beyond its default capabilities.
Stay UpTo Date with Latest Post And news: