October 20, 2023

Add Categories to Pages in WordPress with a Simple Code Snippet

Play Video

Adding categories to pages in WordPress can help you organize your content more effectively. This tutorial will show you how to accomplish this task using the Code Snippets plugin.


Prerequisites

Please make sure you have the following installed and activated:


Step 1: Install the Code Snippets Plugin

  1. Navigate to Plugins > Add New in your WordPress dashboard.
  2. Search for “Code Snippets” in the search bar.
  3. Install and Activate the plugin.

Tip: The Code Snippets plugin allows you to run custom code snippets on your site without editing your theme’s functions.php file. It supports full CSS, JavaScript, Gutenberg, and Elementor integrations.


Step 2: Create a New Code Snippet

  1. Navigate to Snippets > Add New in your WordPress dashboard.
  2. Name it “Add Categories to Pages” to identify it later.
  3. Copy the 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. Navigate to Snippets > Add New.
  5. Paste the copied code into the code area.
    Add categories to pages in WordPress - Add code
  6. Save changes and Activate the snippet.

Tip: Activating the snippet will implement the changes immediately.


Step 3: Assign Categories to Pages

  1. Navigate to Pages > All Pages.
  2. Select a page and click on “Quick Edit”.
    Quick edit category
  3. Assign categories from the categories dropdown.
  4. Update the page.

Note: You can now see categories in the Pages section of your WordPress dashboard.


Add Categories to Pages in WordPress – Conclusion

You’ve successfully added categories to your WordPress pages using the Code Snippets plugin and a snippet from Code Snippets Cloud. This will help you organize your content and make your website more user-friendly.

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 Categories to Pages in WordPress with a Simple Code Snippet
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.