Skip to content

Editing Category Pages in WordPress: A Guide for Beginners and Experts

Héctor de Prada
Editando Categorías de WordPress_ Guía para Principiantes y Expertos Modular

In this article, you will learn how to edit WordPress categories at different levels, from basic to advanced. We will focus on three main sections: one for beginners, one for experts, and a third part on advanced category customization in WordPress.

Why Edit the Category Page in WordPress?

The category page in WordPress is an important part of your website because it is how visitors find specific content. When users click on a category, they are shown a list of posts related to that category. Therefore, it is crucial that your category page is well-organized so that visitors can easily find what they are looking for. Just like when you go to the supermarket… Do you go directly to the aisle where you know what you’re looking for is? Well, it’s the same concept.

Editing Category Page in WordPress – Beginner Level

Create a Category

To create a category in WordPress, follow these steps:

  • a. Go to the WordPress admin panel.
  • b. Click on “Posts” and then “Categories”.
  • c. Enter the name and slug (unique identifier) for the category.
  • d. Optionally, you can add a description.
  • e. Click on “Add New Category”.

Edit a Category

To edit an existing category:

  • a. Go to the WordPress admin panel.
  • b. Click on “Posts” and then “Categories”.
  • c. Hover over the category you want to edit and click on “Edit”.
  • d. Make the necessary changes and save them.

Experts: Plugins and Template Editing

Plugins for Categories

There are several plugins available to enhance category management in WordPress. Some of the most popular ones are:

  • a. Category Order and Taxonomy Terms Order: This plugin allows you to easily reorder categories and custom taxonomy terms by drag and drop.
  • b. Ultimate Category Excluder: It allows you to exclude categories from the main page, archives, feeds, and searches.
  • c. Enhanced Category Pages: It adds additional fields to category pages to improve SEO and the appearance of your categories.
  • d. Post Tags and Categories for Pages: It adds categories to pages.

Edit Category Templates

To edit category templates in WordPress, you need to access the files of your theme. Follow these steps:

  • a. Go to the WordPress admin panel.
  • b. Click on “Appearance” and then “Theme Editor”.
  • c. Look for the “category.php” file in the list of template files.
  • d. Make the desired modifications and save the changes.

This can only be done if you have the file editor enabled within WordPress.

Code Snippets for Templates

1. Display the Category Name

<?php single_cat_title(); ?>

2. Display the Category Description

<?php echo category_description(); ?>

3. Display a List of Subcategories

<?php
  $subcategories = get_categories( array( 'child_of' => get_queried_object_id() ) );
  if ( $subcategories ) {
    echo '<ul>';
    foreach ( $subcategories as $subcategory ) {
      echo '<li><a href="' . get_category_link( $subcategory->term_id ) . '">' . $subcategory->name . '</a></li>';
    }
    echo '</ul>';
  }
?>

4. Display a List of Posts in the Current Category

<?php
  if ( have_posts() ) :
    while ( have_posts() ) : the_post();
      echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
      the_excerpt();
    endwhile;
  endif;
?>

5. Display a Custom Field with Advanced Custom Fields (ACF)

<?php
  $term_id = get_queried_object_id();
  $custom_field = get_field( 'field_name', 'category_' . $term_id );
  if ( $custom_field ) {
    echo '<p>' . $custom_field . '</p>';
  }
?>

Code Example to Display a Category and Description at the Top

<header class="page-header">
    <h1 class="page-title"><?php single_cat_title(); ?></h1>
    <div class="category-description"><?php echo category_description(); ?></div>
</header>

Lastly, what if I want to add categories to pages?

Adding categories to pages in WordPress is not a built-in functionality, but it can be achieved using a plugin or custom code. I’ll explain both methods below:

  1. Using a Plugin:

One of the plugins that allow you to assign categories to pages is “Post Tags and Categories for Pages” (https://wordpress.org/plugins/post-tags-and-categories-for-pages/). To use this plugin, follow these steps:

  • Install and activate the “Post Tags and Categories for Pages” plugin from the WordPress admin panel.
  • Go to “Pages” and select an existing page or create a new one.
  • You will now see a “Categories” and “Tags” section in the right sidebar, just like in posts. Simply select the categories you want for the page and save the changes.
  1. Using Custom Code:

You can add categories to pages by adding a code snippet to your active theme’s “functions.php” file. Here’s the code you need to add:


    function add_categories_to_pages() {
      register_taxonomy_for_object_type( 'category', 'page' );
    }
    add_action( 'init', 'add_categories_to_pages' );
  

Once you have added this code, follow these steps:

  • Go to “Pages” and select an existing page or create a new one.
  • If you don’t see the “Categories” section in the right sidebar, click on “Screen Options” in the top right corner and make sure the “Categories” checkbox is checked.
  • You should now see the “Categories” section in the right sidebar. Simply select the categories you want for the page and save the changes.

Questions about WordPress Categories

How can I sort categories in WordPress?

There are several ways to sort categories in WordPress. One option is to use a category sorting plugin like Category Order and Taxonomy Terms Order, which allows you to drag and drop categories into the desired order. Another option is to use custom code in the functions.php file of your active theme to modify the category order.

Can I assign multiple categories to a WordPress post?

Yes, it is possible to assign a post to multiple categories in WordPress. To do this, edit the post you want to assign to multiple categories and look for the “Categories” section in the editing panel. Check all the categories you want to assign and save the changes.
It’s important to note that assigning a post to multiple categories can impact the organization of content and the navigation of the website.

What is the difference between categories and tags in WordPress?

Categories and tags in WordPress are tools for organizing content. The former is a way to group content into broader topics and is used to organize content into separate sections of the website, such as a navigation bar.
Tags are keywords used to describe content in more detail and are used to link related posts. In general, categories are broader and more structured, while tags are more specific and flexible.

What if I want to display the description at the bottom of the category?

To display the category description at the bottom of the category page, you can add the following code just before the main loop ends (usually marked with endif;) in the “category.php” or “archive.php” file of your theme.

<footer class="category-footer">
    <div class="category-description"><?php echo category_description(); ?></div>
</footer>

What is the benefit of having a description at the top of the category?

Provide context: The description helps visitors understand what the category is about. This is especially useful if the category name is not descriptive enough or if you want to provide additional information about the topic.
Enhance user experience: By including a description, visitors can get a quick overview of what they will find in that category. This allows them to decide whether they want to explore the content further or not, thereby improving navigation and user experience on your website.

Improve SEO: Category descriptions can be helpful in improving the SEO of your website. Search engines like Google crawl and analyze the content of pages, including category descriptions. By including relevant keywords in the description, you can increase the relevance and visibility of the category page in search results.

Now that you’ve learned how to edit category pages in WordPress like a pro, how about learning to optimize your web traffic analysis? Check out our article on the best alternatives to Google Analytics for WordPress.

Héctor de Prada Cofundador Modular
Autor
Héctor de Prada
Cofounder & CEO de ModularDS
Casi 10 años trabajando con WordPress en más de 100 proyectos diferentes. Desde el 2022 asiste y disfruta de todas las WordCamps que puede. Siempre abierto a hablar con otros profesionales del mundo web.

Subscribe to our Newsletter about the web world