How to Add Categories (And Tags) to Pages in WordPress

The three ways to add categories to pages in WordPress: with a plugin, by editing your theme’s functions.php, and by creating a custom plugin for the job.

Published Categorized as WordPress

By default, every WordPress website has two post types: posts and pages. Posts are organized into categories and tags, whereas pages are hierarchical and organized into parent and child pages.

But what if you want to break the mold and be able to assign categories (and maybe tags) to your pages in WordPress? This tutorial will show you exactly how to do this, with and without a third-party plugin.

With a Plugin

The fastest and easiest way to add categories to pages in WordPress is to use a plugin that handles the technical aspect of this task for you.

There are a number of plugins for this in the WordPress plugin repository. At the time of publishing this guide, Sandeep Singh’s Create and Assign Categories For Pages seemed to have the most active installations and recent updates.

Step-by-step guide:

Step 1. In WordPress admin, go to “Plugins” > “Add New.” Find “Create and Assign Categories For Pages” and, when you do, click on the “Install Now” button.

Installing the plugin in WordPress admin

Step 2. Once the plugin has finished installing, click on the blue “Activate” button.

Activating the plugin

Step 3. That’s it. You can now assign categories (and tags) to WordPress pages. To verify that everything went well, hover over “Pages” in WordPress. You should see links to “Categories” and “Tags.”

Verifying that the plugin works

The categories and tags will be shared between pages and posts. So, if you create a new category or tag from the “Posts” section, you will also be able to see and assign it in the “Pages” section.

Without a Plugin

There are two ways to add categories to pages without using a third-party plugin: One is to edit your theme’s functions.php file, and the other is to create your own custom plugin.

Below, I explain when to go for each, and how exactly to do it.

By Editing Your Theme’s Functions.php

To add categories to WordPress pages without a plugin, add the following PHP code to the bottom of your theme’s functions.php file, immediately above the closing ?> tag:

// Add the category taxonomy to the page object type
function add_categories_to_pages() {
  register_taxonomy_for_object_type('category', 'page');
}

// Display categories for pages in WordPress admin
add_action( 'init', 'add_categories_to_pages' );

Do this only if your theme is custom built or if you’re using a child theme.

Otherwise, this code will be overwritten each time you update your theme, and the category taxonomy will be removed from the page object type.

This will not delete the existing categories on the pages—you won’t have to go back and reassign categories to old pages—but you will have to add the above code to your functions.php again after each update.

By Creating a Custom Plugin of Your Own

If you don’t want to install third-party plugins, and yet you’re not using a custom or child theme, the best way to add categories to WordPress pages is to create a custom plugin for the job.

Creating your own WordPress plugin may sound intimidating, I know, especially if you’re familiar with PHP but not WordPress. The good news is that this is easier than most people think.

Custom Plugin Only for Categories

Create a new folder named custom-add-categories-to-pages. In it, create a PHP file called plugin.php with the following contents:

<?php
/**
 * Plugin Name: Custom Add Categories to Pages
 */

// Add the category taxonomy to the page object type
function add_categories_to_pages() {
  register_taxonomy_for_object_type('category', 'page');
}

// Display categories for pages in WordPress admin
add_action( 'init', 'add_categories_to_pages' );
?>

Custom Plugin for Categories and Tags

If you also want to add tags to your pages, use the following code:

<?php
/**
 * Plugin Name: Custom Add Categories and Tags to Pages
 */

// Add the category taxonomy to the page object type
function add_categories_to_pages() {
  register_taxonomy_for_object_type('category', 'page');
  register_taxonomy_for_object_type('post_tag', 'page');
}

// Display categories for pages in WordPress admin
add_action( 'init', 'add_categories_to_pages' );
?>

Installing and Activating the Custom Plugin

There are two methods for installing the plugin.

Method #1: Archive and upload via WordPress admin

You can archive the custom-add-categories-to-pages folder in a .zip file named custom-add-categories-to-pages.zip, then go to WordPress admin > “Plugins” > “Add New” > “Upload Plugin” and install and activate the plugin as usual.

Method #2: Upload unarchived folder to /wp-content/plugins/ via FTP

Or, using FTP or SFTP, you can upload the add-categories-to-pages folder to your WordPress instance’s /wp-content/plugins/ folder, go to WordPress admin > “Plugins” > “Installed Plugins,” then locate your plugin and activate it as usual.

That’s pretty much it! As soon as you’ve installed and activated your custom plugin, you should be able to manage and add categories to pages.

Image courtesy of Maksym Kaharlytskyi /Unsplash

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *