Changing WordPress Default Taxonomies

Changing WordPress Default Taxonomies

Sometimes the native out-of-the-box WordPress Taxonomies ‘Categories’ & ‘Tags’ just don’t make sense when structuring the content. Or maybe, said taxonomies play an explicit role in  dynamically generated content and you need to make is EXTRA clear to the end user what exactly these ‘tags’ or ‘categories’ actually DO? A recent example was website where categories where uses to categories the physical demand of a given bike route.  It’s also possible you just want to get rid of a given taxonomy as it’s not being used and adds additional complexity to a the WordPress backend wich is likely already overwhelming for most clients and first time users.

There is no native way to unregister a taxonomy from WordPress. However, that doesn’t mean it can’t be done. If you’d rather and then register your new taxonomy, or unregister and leave it  that, the following snippet will get you there.

[php]
<?php /**
* Remove built in taxonomies
* @author: Franz Josef Kaiser
*/
function unregister_taxonomy( $taxonomy )
{
global $wp_taxonomies;

// Here we can take a separated look at the built in taxonomies
echo ‘
‘;
/*
print_r( $wp_taxonomies[‘category’] );
print_r( $wp_taxonomies[‘post_tag’] );
print_r( $wp_taxonomies[‘nav_menu’] );
print_r( $wp_taxonomies[‘link_category’] );
print_r( $wp_taxonomies[‘post_format’] );
*/

foreach ( $wp_taxonomies as $tax => $data )
{
// Only deal with _builtin taxonomies
if ( $data->_builtin === true )
{
// Print out them name if it’s builtin; check
# print_r( $tax );

// Now let’s unset "category"
if ( $tax == ‘category’)
{
// Check to be sure if we’re dealing with the right one
# print_r( $tax );
unset( $wp_taxonomies[$tax] );
}
}
}
// double check after wards: have we been successful?
# print_r($wp_taxonomies);
echo ‘
‘;
}
add_action( ‘init’, ‘unregister_taxonomy’ );

function check_unset_category() {
global $wp_taxonomies;

// Now let’s check inside our viewport (after footer) if we real got rid of the taxonomy
echo ‘
‘;
print_r( $wp_taxonomies );
echo ‘
‘;
}
add_action( ‘wp_footer’, ‘check_unset_category’, 999 );
?>
[/php]

…Or, you can change the labels in the WordPress admin area with the init and admin_init hooks.

[php]
function change_category_taxonomy_label() {
global $wp_taxonomies;

$labels = $wp_taxonomies[‘category’]->labels;

if(!empty($labels)){
$search = array(‘Categories’, ‘Category’, ‘category’);
$replace = array(‘Physical Ratings’, ‘Physical Rating’, ‘physical rating’);

foreach ($labels as $key => $label) {
//search and replace category with new TAX labels
$label = str_replace($search, $replace, $label);

//Update the labels with new values
$wp_taxonomies[‘category’]->labels->$key = $label;
}
}
//lastly, update label
$wp_taxonomies[‘category’]->label = ‘Physical Rating’;

}

function jwh_manage_columns( $columns ) {

$columns[‘categories’] = ‘Physical Ratings’;
return $columns;
}

function jwh_column_init() {
add_filter( ‘manage_posts_columns’ , ‘jwh_manage_columns’ );
}
add_action( ‘admin_init’ , ‘jwh_column_init’ );
[/php]