What are custom taxonomies in WordPress? • Yoast


In WordPress, content can be grouped using categories and tags by default. WordPress calls these groups taxonomies. When you are serious about your content and have a lot of it, it will pay off to create other groups as well. By creating these custom taxonomies, you’re making your life as a content writer easier. More importantly, you’ll structure your website to your best effort for your visitors. They’ll be able to locate content that’s relevant to them and find related content more easily. This article will dive into the use of custom taxonomies.

Hierarchical versus non-hierarchical

WordPress introduced the concept of tags in version 2.3. As described by Wikipedia, a tag is ‘a non-hierarchical keyword or term assigned to a piece of information.’ This means WordPress has had a hierarchical way of classifying information (categories), and a non-hierarchical way of organizing information (tags) since version 2.3. As far back as 2006 (!), people were discussing the fact that tags are not categories. The problem is that WordPress calls them both ‘taxonomies,’ but that’s not entirely correct. The word taxonomy assumes a hierarchy of sorts, as explained on another Wikipedia page

With version 2.8, WordPress introduced custom taxonomies. Or actually, allowed easier access to the already available backend for custom taxonomies. These custom taxonomies can be either non-hierarchical (e.g. ‘tag’-like) or hierarchical (e.g. ‘category’-like). But for now, only the non-hierarchical taxonomies benefit from the smooth integration. These are more like actual taxonomies though, as they add a kind of hierarchy to the tag structure.

Let me give you an example: you could have a ‘People’ and a ‘Places’ taxonomy. Say, you write a new post and decide to add a keyword in the ‘People’ taxonomy. By doing that, you’re saying that it’s a keyword (or tag, if you want) of the type ‘People,’ so it is hierarchical in a way. But it also makes the keyword that much more informative, as it adds another layer of information.

Some years ago, Roy Huiskes made this visual for us by making a graphical explanation of the subject:

custom taxonomies

Fun fact: That People taxonomy section in the image above would include some more branches nowadays.

You can imagine using this for locations, or employees on a company site, but also writers on a book site, destinations on a travel site, etcetera. It groups items in a convenient way, both for maintenance and your visitors.

Custom taxonomies in WordPress

Adding custom taxonomies in WordPress isn’t that hard. To manually register a taxonomy, you can use the register_taxonomy() function. Most WordPress developers have probably used this one time or another, right?

WordPress.org has an example of how to approach this for a People taxonomy:

function people_init() {
	// create a new taxonomy
	register_taxonomy(
		'people',
		'post',
		array(
			'label' => __( 'People' ),
			'rewrite' => array( 'slug' => 'person' ),
			'capabilities' => array(
				'assign_terms' => 'edit_guides',
				'edit_terms' => 'publish_guides'
			)
		)
	);
}
add_action( 'init', 'people_init' );

This piece of code adds a meta box to your WordPress post edit screens, that looks like the tag box. It even works in the same way. I’m not a fan of tag clouds, but yes, in theory, you could even create a cloud for your new taxonomy. For a more in-depth explanation, check this post by wpmudev.org (2016).

These custom taxonomies can be public and private, which also makes them extremely useful for internal grouping of elements as well. I can imagine grouping VIP users, social influencers; you name it. 

Note: (Custom) Taxonomies and Gutenberg

As Matt Cromwell describes, “Gutenberg is the future of content in WordPress. It will deliver the elegance of Medium but with far more power and flexibility of layouts and content types”. But Gutenberg is currently in development, and 99% of WordPress users probably won’t see any of it until it’s finished.

However, just last week, my colleague Tim added an issue to the WordPress/Gutenberg Github repo: Gutenberg shows private taxonomies in Category and Tag lists. Just dropping this here as a note, as I am sure the development team fixes this before releasing Gutenberg to the public. But if you are test-driving Gutenberg on a live site, and you are using custom taxonomies somewhere on that site, it could be something to check. Just to be sure!

How are you using custom taxonomies?

So, in conclusion, custom taxonomies can be very useful. If you have loads of content and want to create order, for both yourself and your users, you could use them.

That leaves me with two questions: Are you using custom taxonomies and if yes, how did you add these to your site? I’m looking forward to your answers in the comments!

Read more: ‘Using category and tag pages for SEO’ »



Source link

?
WP Twitter Auto Publish Powered By : XYZScripts.com