Over a million developers have joined DZone.

De-registering a WordPress Custom Taxonomy

DZone's Guide to

De-registering a WordPress Custom Taxonomy

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

Now if you have been following my posts on custom taxonomies How To Programatically Add Terms to a WordPress Taxonomy and How To Add A Custom Taxonomy To Your Theme, you will know how to register a custom taxonomy and how to register terms for that taxonomy. However what do you do if you want to de-register a taxonomy?

If you look for a function in the API or on the codex then you might be hard pressed to find one. However there is a way to do it. It does mean accessing variables in the WordPress framework in a way which is, effectively, unsupported but it can be done.

But more to the point why would you want to? Well let’s say you have a plugin which allows you to manage taxonomies. You can add new ones, add terms etc. If you update a taxonomy then you might need to unregister that taxonomy and then re-register it in order to display the changes that have been made.

Another example could be that you you have a very customised theme, and you want to remove the standard Tags and Categories taxonomies. You can also use the following technique to do that as well. So how does it work.

Well in WordPress taxonomies are held in a gloabl array called $wp_taxonomies, if you get access to this array using the global keyword you can then unset the value for the custom taxonomy and the taxonomy is no longer registered.

for example :-

global $wp_taxonomies;
	if( isset( $wp_taxonomies[ 'my_taxonomy' ] ) ) {
		unset( $wp_taxonomies[ 'my_taxonomy' ] );

Just be aware that as this is unsupported if the name of the $wp_taxonomies ever changed you would also need to update your plugin or theme code to follow.

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.


Published at DZone with permission of Chris Odell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}