Over a million developers have joined DZone.

De-registering a WordPress Custom Taxonomy

· Web Dev Zone

Learn why developers are gravitating towards Node and its ability to retain and leverage the skills of JavaScript developers and the ability to deliver projects faster than other languages can.  Brought to you in partnership with IBM.

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.

Make the transition to Node.js if you are Java, PHP, Rails or .NET developer with these resources to help jumpstart your Node.js knowledge plus pick up some development tips.  Brought to you in partnership with IBM.

Topics:

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}