June 13, 2023

Add Page Categories in WordPress Using Code Snippets

Play Video

Adding page categories in WordPress can be very useful when you have numerous pages on your website and you want to group them into categories, or when you’re using templates and want to apply them to a specific set of pages. It is a feature that many users wish was a built-in functionality. Unfortunately, by default, WordPress does not offer this option. However, there’s a simple solution to this problem – using a free code snippet. This tutorial by Web Squadron will guide you through the process of adding categories to your WordPress pages using the Code Snippets plugin.

Steps to Add Page Categories in WordPress

  1. Install the Code Snippets Plugin
    Go to your WordPress dashboard, navigate to ‘Plugins’, and click ‘Add New’. In the search bar, type ‘Code Snippets’. Install and activate the plugin.
  2. Add a New Snippet
    In your WordPress dashboard, go to ‘Snippets’ and click ‘Add New’. Give your new snippet a title.
  3. Copy the Code
    Copy the provided code below:

    add_action( 'init', 'add_categories_to_pages' );
     /*
      * Add CATEGORIES to pages
      */
    function add_categories_to_pages() {
      
      register_taxonomy_for_object_type( 'category', 'page' );
      
    }

    Source: Code Snippets

  4. Paste the Code
    Return to your WordPress dashboard and paste the copied code into your new snippet. Click ‘Save Changes’ and ‘Activate’.
  5. Assign Categories to Pages
    Now, when you go to ‘Pages’, you’ll see a new ‘Category’ column. You can edit each page to assign it to a category. You can also create new categories specifically for your pages.

Why you should use WordPress page categories

The ability to add categories to WordPress pages can greatly enhance your website’s organization and user experience. It allows you to group related pages together, making it easier for visitors to find the content they’re interested in. Moreover, if you’re using templates, you can apply them to a specific set of pages based on their category, streamlining your design process. Here are some examples of why WordPress page categories usecases:

  • E-commerce Store
    Imagine you’re running an online store with hundreds of product pages. With the ability to categorize these pages, you can create a more structured shopping experience for your customers. For instance, you could have categories for ‘Men’s Clothing’, ‘Women’s Clothing’, ‘Accessories’, and so on. This not only makes it easier for customers to find what they’re looking for, but it also allows you to set up category-specific promotions or design elements.
  • Educational Website
    Suppose you have a website offering various online courses. By categorizing your course pages, you can create a more streamlined learning path for your students. For example, you could have categories like ‘Beginner Courses’, ‘Intermediate Courses’, ‘Advanced Courses’, etc. This helps students navigate your offerings more easily and find the courses that suit their skill level.
  • Blog or News Site
    If you’re running a blog or news site covering a wide range of topics, page categories can help your readers find the content they’re interested in. For instance, you could have categories like ‘Tech News’, ‘Lifestyle Articles’, ‘Travel Guides’, etc. This not only improves the reader experience but also allows you to tailor your design and content strategy for each category.

Best Practices for Using WordPress Page Categories

Once you’ve learned how to add categories to your WordPress pages, it’s important to use this feature effectively. Here are some best practices to keep in mind:

  1. Be Consistent
    Try to maintain consistency in how you categorize your pages. This makes it easier for users to understand your site structure and find what they’re looking for.
  2. Don’t Overdo It
    While it’s possible to assign multiple categories to a single page, it’s usually best to keep it simple. Assigning too many categories to a page can confuse users and dilute the effectiveness of your categorization.
  3. Use Descriptive Category Names
    The names of your categories should clearly indicate what users can expect to find in them. Avoid vague or overly broad category names.
  4. Consider SEO
    Page categories can potentially impact your SEO. Try to choose category names that align with the keywords your target audience might use to search for your content.
  5. Review and Adjust
    As your website grows and evolves, you might need to add new categories or reorganize existing ones. Regularly review your category structure to ensure it continues to serve your needs and those of your users.

Common Issues

  • Code Not Working
    If the code snippet doesn’t work, make sure you’ve copied it correctly from Code Snippets Cloud and pasted it into the correct field in your WordPress dashboard.
  • Categories Not Showing Up
    If the ‘Category’ column doesn’t appear in ‘Pages’ after activating the snippet, try deactivating and reactivating the Code Snippets plugin.

Required Resources

Code Snippets Logo
Free Options
Credit to Web Squadron
Web Squadron is a popular YouTube channel dedicated to providing informative tutorials, tips, and insights on web development and design. With a strong focus on WordPress and website builders like Bricks Builder, the channel aims to help users of all skill levels, from beginners to advanced developers, create and optimize their websites. By offering easy-to-understand, step-by-step guidance, Web Squadron provides practical and valuable content.
Visit
Add Page Categories in WordPress Using Code Snippets
Welcome back!
Enter your Helwp credentials to sign in.

No Account yet? Sign Up

My Account
Menu
Give Feedback
Describe your feedback *
Rate Helwp
Share
Facebook
Twitter
LinkedIn
Reddit
Email
WhatsApp
Telegram
Pocket
Report
Problem *
Describe the problem
Want us to reply?
Your E-Mail
Affiliate Disclosure

At Helwp, we’re committed to transparency and honesty. Therefore, we want to inform you that some of the links on our website are affiliate links. This means that, at no additional cost to you, we may earn a small commission if you click through and make a purchase.

We only promote products or services that we genuinely believe in. These affiliate commissions help us to maintain the website and continue to provide you with free, high-quality WordPress content.

If you are interested in how you can support us even further, check out our support page.