How to Enhance WordPress Pages with Categories and Tags: A Step-by-Step Guide

Contents

Build your own WordPress Support Plan

Expert, yet affordable WordPress support & maintenance plans.
View our pricing

TL;DR: Learn how to add categories and tags to your WordPress pages to improve organisation and SEO. This guide covers both using existing taxonomies and creating separate ones, and it explains how to implement these functionalities using the Code Snippets plugin for easy and safe customisation.

Introduction

If you’re familiar with WordPress’s categories and tags for posts, you already know how valuable they are for organising content and improving SEO. However, WordPress does not support categories and tags for pages by default. This guide will show you how to extend these functionalities to pages, making your site more manageable and SEO-friendly.

Why Add Categories and Tags to WordPress Pages?

  • Better Organisation: Categorising and tagging pages help in structuring your site content logically.
  • Improved SEO: Search engines can better understand your content, potentially improving your rankings.
  • Enhanced User Experience: Visitors can easily navigate through related pages, increasing engagement.

How to Enable Categories and Tags on WordPress Pages

Step 1: Create a Function to Enable Categories and Tags

To add categories and tags to pages using the existing post taxonomies, you need to create a custom function. This can be done by modifying your theme’s functions.php file or using a plugin like Code Snippets.

Code to Add Categories and Tags to Pages

function add_categories_and_tags_to_pages() {
    // Register categories for 'page' post type.
    register_taxonomy_for_object_type('category', 'page');
    // Register tags for 'page' post type.
    register_taxonomy_for_object_type('post_tag', 'page');
}

// Hook into the 'init' action to execute the function.
add_action('init', 'add_categories_and_tags_to_pages');

Step 2: Add the Code Using Code Snippets

  1. Install and Activate Code Snippets Plugin:
    • Go to your WordPress dashboard.
    • Navigate to Plugins > Add New.
    • Search for “Code Snippets”.
    • Install and activate the Code Snippets plugin.
  2. Add a New Snippet:
    • Go to Snippets > Add New.
    • Give your snippet a descriptive title, like “Enable Categories and Tags for Pages”.
    • Copy and paste the code provided above into the Code field.
    • Click “Save Changes and Activate”.

This will enable categories and tags for WordPress pages using the existing category and post_tag taxonomies.

Creating a Separate Category and Tag Taxonomy for Pages

For those who prefer a separate category and tagging system for pages, you can create a new taxonomy distinct from the one used for posts.

Step 1: Create a Function to Enable Separate Categories and Tags

To add separate categories and tags for WordPress pages, you need to create custom taxonomies. This can be done by modifying your theme’s functions.php file or using a plugin like Code Snippets.

Code to Add Separate Categories and Tags to Pages

function create_page_category_taxonomy() {
    // Labels for the custom category taxonomy.
    $labels = array(
        'name'                       => _x('Page Categories', 'taxonomy general name'),
        'singular_name'              => _x('Page Category', 'taxonomy singular name'),
        'search_items'               => __('Search Page Categories'),
        'all_items'                  => __('All Page Categories'),
        'parent_item'                => __('Parent Page Category'),
        'parent_item_colon'          => __('Parent Page Category:'),
        'edit_item'                  => __('Edit Page Category'),
        'update_item'                => __('Update Page Category'),
        'add_new_item'               => __('Add New Page Category'),
        'new_item_name'              => __('New Page Category Name'),
        'menu_name'                  => __('Page Categories'),
    );

    // Register the custom taxonomy for categories.
    register_taxonomy('page_category', 'page', array(
        'hierarchical'          => true,
        'labels'                => $labels,
        'show_ui'               => true,
        'show_admin_column'     => true,
        'query_var'             => true,
        'rewrite'               => array('slug' => 'page-category'),
    ));
}

function create_page_tags_taxonomy() {
    // Labels for the custom tag taxonomy.
    $labels = array(
        'name'                       => _x('Page Tags', 'taxonomy general name'),
        'singular_name'              => _x('Page Tag', 'taxonomy singular name'),
        'search_items'               => __('Search Page Tags'),
        'popular_items'              => __('Popular Page Tags'),
        'all_items'                  => __('All Page Tags'),
        'edit_item'                  => __('Edit Page Tag'),
        'update_item'                => __('Update Page Tag'),
        'add_new_item'               => __('Add New Page Tag'),
        'new_item_name'              => __('New Page Tag Name'),
        'separate_items_with_commas' => __('Separate page tags with commas'),
        'add_or_remove_items'        => __('Add or remove page tags'),
        'choose_from_most_used'      => __('Choose from the most used page tags'),
        'not_found'                  => __('No page tags found.'),
        'menu_name'                  => __('Page Tags'),
    );

    // Register the custom taxonomy for tags.
    register_taxonomy('page_tag', 'page', array(
        'hierarchical'          => false,
        'labels'                => $labels,
        'show_ui'               => true,
        'show_admin_column'     => true,
        'query_var'             => true,
        'rewrite'               => array('slug' => 'page-tag'),
    ));
}

// Hook into the 'init' action to execute the functions.
add_action('init', 'create_page_category_taxonomy');
add_action('init', 'create_page_tags_taxonomy');

Step 2: Add the Code Using Code Snippets

  1. Add a New Snippet:
    • Go to Snippets > Add New.
    • Give your snippet a descriptive title, like “Enable Separate Categories and Tags for Pages”.
    • Copy and paste the code provided above into the Code field.
    • Click “Save Changes and Activate”.

This will enable separate categories and tags specifically for WordPress pages, allowing for more granular control over your page organisation.

Conclusion

Adding categories and tags to WordPress pages can greatly benefit your site’s organisation, SEO, and user experience. Whether you choose to use the existing post taxonomies or create a separate category and tagging system for pages, the steps provided in this guide make the process straightforward. Use the Code Snippets plugin to easily implement these changes without touching your theme’s code, ensuring a smoother and safer customisation experience. Start categorising and tagging your pages today for a more structured and optimised WordPress site.

Does that sound too complicated, or you don’t have the time? Get in touch with us and one of our WordPress experts can do this for you.

Written By
John
Support @ WP Helper
You will also like these articles

Relax Knowing Your WordPress Site Is Secure & Running Smoothly 24/7

Let us manage your WordPress site, everything from security to updates will be taken care of. Support plans also come with dedicated support so we can do anything from adding content to customising your site for you.

Same Day Professional WordPress Support

Get WordPress Support Today

Need help with a single WordPress problem, today? We can help with anything from adding analytics tracking code to site hack recovery. Full money back guarantee on all jobs.

1. Submit a Support Request

Use our support ticket form below to send details of your problem to our developers.

2. Get a Quote

We will review your request and provide a quote within 24 hours (but usually within a few hours).

3. We fix your WordPress problem

Our team will begin fixing your WordPress problem the same day.

4. 100% Money Back Guarantee

If we can’t fix the problem for the amount quoted we will refund you 100%.

  • Do you have a screenshot of the issue or have a copy of the theme or plugin that is at fault? If you want to upload php, html or css please zip first.
    Drop files here or
    Accepted file types: jpg, jpeg, png, pdf, zip, gzip, rar, doc, txt, Max. file size: 15 MB, Max. files: 10.