you are a WordPress website or blog owner, you must have heard about the term Taxonomy which is mainly used to classify and group the content of your WordPress site into different groups or classifications.
In today’s article, we will explain this concept in detail and show you how important it is for your website. We will also explain how to create custom classifications and explain how to deal with them on websites that need specific requirements in two ways (through ready-made plugins, and manually through code).
What is Taxonomy in WordPress?
Classification on a WordPress site – or on any website in general – is a way that enables you to classify and sort the content of your site or blog and organize it into different categories.
For example. If you have an educational website through which you provide training courses on various topics, you will need to add a classification for each training course that you add to the site. For example (computer, mathematics, English language, electronic marketing , etc.)
These classifications enable you to organize site courses into different sections so that your site content does not become random, crowded, and difficult to manage. In addition, it contributes to improving the search engines of your site and helps it identify related content.
By default, WordPress has two types of classifications automatically built into it to help you with this task: categories and tags, which usually appear on the left side of the component editor when editing any article on the site.
To avoid confusion between the concept of classification (Taxonomy) in the general sense, which we are talking about in this article, and the classification (Category) that the WordPress system provides to you itself – which is considered one of the types of general classifications – we will from now on refer to the first as taxonomy and the second as classification.
What is the difference between categories and tags in WordPress?
As we previously mentioned, when publishing any article on your WordPress site, you can add classifications and tags to this article , both of which are considered a type of taxonomy that WordPress provides in a ready-made way to organize the content. Here are the most important differences between categories and tags:
- Categories are used to group similar articles on the site together, while tags are used to describe the site’s articles with semantic words that describe their content and facilitate the process of searching for articles that include the same tags.
- You can add site-specific categories, write a description for them, and edit them through your WordPress site’s control panel > Articles > Categories . Likewise, you can add and edit tags through your WordPress site’s control panel and choose < Articles > Tags .
- Categories in WordPress are mandatory, as you must put at least one category for your article, and if you do not specify any category, it will be published under the default category (Uncategorized), while tags are optional and you are not obligated to place them for your articles.
- Categories in WordPress are organized hierarchically. You can create a parent category and child categories for this category, while tags cannot be hierarchical, but rather be all on one horizontal level (flat).
What is the difference between taxonomy and categories and tags in WordPress?
Taxonomy refers to the concept of collecting website posts in general. As for categories and tags, they are ready-made methods that the WordPress system provides for you to collect your articles and organize them hierarchically or horizontally.
For example, suppose you have a website that provides food recipes. In this case, you can classify recipes in the following hierarchical manner according to countries (a father’s classification for Arabic recipes, with 4 sons’ classifications below it (Levantine, Gulf, Egyptian, Moroccan recipes). A second father’s classification for international recipes, and 3 sons’ classifications below it. It (Italian, Chinese, Indian recipes)
You can also specify tags for specific recipes on your site to show, for example, the most important ingredients included in these recipes (meat, vegetables, starches, eggs…) to help find specific recipes that include specific ingredients, even if they fall within the classifications of different countries.
Most sites may just customize content using these categories and tags provided by WordPress, but sometimes you may need to group your site content based on different criteria.
In the previous example of the food recipes website, what if you needed to classify the recipes based on an additional criterion, such as classifying them based on the preparation time required to prepare and cook the entire recipe? How will you add this feature?
In this case, you will need to create a new taxonomy dedicated to your site, and give it the name you want, for example, Cooking time. You will also need to create the vocabulary or terms that this taxonomy includes, such as (short, medium, long), and link this taxonomy to your site’s articles. With recipes.
It is worth noting that custom taxonomy in WordPress can be hierarchical, similar to categories, or be at a single level, such as tags. It depends on your site’s specific requirements.
How to create a custom Taxonomy in WordPress?
There are several ways through which you can create your own custom taxonomy on a WordPress site, and the easiest of these methods is by using ready-made WordPress plugins. Fortunately, there are many plugins that provide the advantage of creating custom taxonomies in WordPress easily and without the need for programming experience. The most prominent of these plugins are:
- Custom Post Type UI : This plugin was created by Pluginize to enable website owners to manage both custom post types and custom classifications for their WordPress site using an easy-to-use graphical interface.
- Pods – Custom Content Types and Fields : This add-on also enables you to expand and create custom content types including custom post types, custom taxonomies, and your own advanced content types easily with one click.
Read also: Custom Post and ways to use and create it in WordPress
It is also possible to create custom categories on your site through code, but this method requires you to have knowledge of writing and modifying code in WordPress, dealing with template files and plugins, and the basics of how hooks work in WordPress .
1. Create a custom Taxonomy using the Custom Post Type UI plugin.
In this paragraph, we will explain how to use the plugin to create custom Taxonomy categories for a WordPress site using the Custom Post Type UI plugin.
This plugin includes a lot of details because it is used to create both custom posts and custom categories on a WordPress site, as mentioned in the previous paragraph.
But in this article, we will use the plugin to create a custom category only, and we will call it (Cooking time), and we will attach it to the default WordPress articles, and you can of course attach it to any custom content type that you create on your site.
Go to the control panel and choose Add-ons > Add New> and search for the name of the add-on Custom Post Type UI , then install the add-on and activate it on your site.
After activating the extension on your site, you will notice that a new item appears in the sidebar of your site’s control panel called CPT UI . Click on this name and choose from the menu that appears the option Add/Edit Taxonomy to add and edit the custom taxonomy on the site.
A window for setting up the new Taxonomy will appear. This window includes a very long list of different options for customizing Taxonomy, but here we will stick to the basic settings.
First, we will set up the basic options in the Basic Settings section shown in the following image (the fields with * next to them are mandatory fields and the other fields are optional):
- Taxonomy Slug: From here we define the friendly name for taxonomy (cook_time). This name must contain numbers and letters in English only, and uppercase letters are automatically converted to lowercase letters, as this name is used in the URL and in WordPress queries.
- Plural Label: From here we define the name taxonomy in the plural form (cook_times)
- Singular Label: From here we specify the name of the taxonomy in the singular form (cook_time)
- Auto-populate labels Through this option, you can allow the extension to automatically fill in the rest of the label fields on your behalf.
- Attach to Post Type: Through this option you can specify what type of posts you want to associate this taxonomy with (here we chose WP Core articles).
There are several other settings that you can customize from this window. For example, in the settings section, you can specify whether this taxonomy is a general classification through which users can filter, filter and search content, or a private classification.
You can also specify whether taxonomy is hierarchical, meaning whether it uses a parent/child relationship such as categories or a single-level list such as tags. Depending on the options you choose, the taxonomy will appear on the site.
The plugin has many other options, and in this article we have limited ourselves to the basic options related to creating a hierarchical taxonomy to classify our site’s articles. I suggest you take a look at the full list of options on the official page of the extension and configure it to suit your requirements.
After you have finished selecting all the options, click on the Add Taxonomy button and go to the site control panel > articles and view the site’s articles, then add a new article or edit a previous article. You will notice that the new taxonomy appears as a submenu within the list of articles. When you click on it, the vocabulary setting page will appear for you. The classification is as follows:
Since we added this classification to the default articles in WordPress and specified that it will appear hierarchically, when we go to edit any article on the site, this classification will appear in the sidebar of the site editor when editing articles.
From here you can also create new terms related to the new Taxonomy to group the site’s recipes according to the cooking time required for them. For example, add a new term to recipes by clicking on the Add new cook_time link and add a new time to recipes that take more than two hours to cook, as shown in the following image:
2. Create custom Taxonomy manually through code
In this paragraph, we will explain how to add a custom taxonomy category to a WordPress site through code without the need for external plugins.
We will be adding our code to the website template, so we need to access the functions.php file for our current website template.
You can access this file through the following path: public_html/wp-content/theme_name, as this is the name of the template activated on your site. And open the function.php file in any code editor
Or choose from the control panel Appearance Template File Editor and select the functions.php file for the template to edit it from within the control panel and write at the end of the following code and save the changes.
This code creates a new taxonomy called cooking time, and here we will make it a hierarchical taxonomy like the categories. You may, of course, need to modify this code depending on the nature of the taxonomy you want to create on your site.
The taxonomy we created uses the init hook to hook the custom function wpar_register_taxonomy_cooking_time() which involves calling the ready-made WordPress function register_taxonomy() responsible for creating or modifying taxonomy which has the following general form
We can pass three arguments to the function as follows
- $taxonomy is a string representing the name of the taxonomy cooking_time
- $object_type An array or string specifying the post type we want to associate taxonomy with, which in our case is the default WordPress posts [‘post’]
- $args An array of parameters that define taxonomy specifications
To learn more about how to use this function and all the parameters and specifications that can be specified for Taxonomy, I recommend seeing the following link.
After saving the changes to the template functions script file functions.php, we can move again to the site control panel < Articles < We notice the appearance of a new item called cooking_time. By clicking on it, the window appears that enables us to add vocabulary specific to the new Taxonomy as follows:
Now, if we create or modify any article on our site, we will notice that the custom taxonomic name “cooking time” appears on the sidebar in the article editing window under the tags so that we can classify our articles accordingly as follows:
It is preferable to make these software modifications within the Son template so that we do not lose the modifications you made if you update the site template. Alternatively, it is also possible to create a custom add-on and include the code through it within the site. I recommend checking out the following link to learn more about customizing taxonomy programmatically in WordPress.
Read also: How to develop WordPress plugins yourself to automate functions
Conclusion:
In today’s article, we learned about the concept of taxonomy and its importance in WordPress sites that need custom classification requirements for content. We also learned how to add it to a WordPress site and how to customize it on the site in several ways. All you have to do is choose the method that suits you and organize the content of your site through it.
Do you use a special Taxonomy taxonomy on your website? Tell us why you use it and how you set it up in the comments below the article.
Leave a Reply