What are Terms in WordPress?

In WordPress, the concept of taxonomy is used to categorize and tag content. Items that belong to a taxonomy are referred to as terms. For instance, if a website sorts content into the categories of books, politics, and blogging, each of these categories is a term within the taxonomy known as ‘category’.

Template Tags

Initially, WordPress offered template tags exclusively for displaying categories and tags. However, with the introduction of custom taxonomies, new template tags became available to manage the display of terms. These can be applied to both default and custom taxonomies.

Example of Template Tags

An instance of utilizing template tags for terms is the the_terms() function. This function outputs the terms that are part of a custom taxonomy. The user can also format the output by altering the parameters.

the_terms( $post->ID, 'custom_taxonomy_name', 'Before: ', ', ', ' After' );

Functions in Terms

Functions that deal with terms have specific uses and parameters. For example, the the_terms() function can be tailored to make the output fit within a specific design layout.

Display Methods

Hard Coded through PHP

Developers often use hard coding, which involves writing out the code manually, to display terms in custom taxonomies. This method is often more fitting for websites that have been customized to a significant extent.

Widgets and Plugins

Pre-built WordPress templates that are employed across multiple sites often use widgets and plugins for displaying terms. This method is generally more user-friendly and is easier for those who may not have advanced coding skills.

Short Codes

Terms can also be displayed using shortcodes. These codes are more convenient for administrators who aren’t familiar with coding. Although using shortcodes initially requires some coding, the ongoing use of the feature is simplified.

echo do_shortcode('[custom_shortcode]');

Custom Taxonomies

The capability to create custom taxonomies has opened up more possibilities for sorting content in a WordPress website. Like default taxonomies such as categories and tags, custom taxonomies also contain terms.

the_terms() Function in Custom Taxonomies

The the_terms() function is especially useful when dealing with custom taxonomies. The function displays terms that belong to a particular custom taxonomy and allows the user to format them in a way that is suitable for their website’s design.

the_terms( $post->ID, 'your_custom_taxonomy', 'Before: ', ', ', ' After' );

Parameters of the_terms() Function

The the_terms() function comes with various parameters that let you tailor its behavior. These parameters include:

  • $id: ID of the post
  • $taxonomy: Name of the taxonomy
  • $before: Text or HTML to display before the terms
  • $sep: Separator between the terms
  • $after: Text or HTML to display after the terms

Convenience for Administrators

One advantage of using widgets, plugins, and shortcodes for displaying terms is the ease of use for administrators who may not be well-versed in coding. This makes it easier for such users to control how terms appear on their websites.

Leave a Comment

Your email address will not be published. Required fields are marked *

Share via
Copy link