Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Last active June 21, 2019 21:44
Show Gist options
  • Save franz-josef-kaiser/870890 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/870890 to your computer and use it in GitHub Desktop.
Allows unregistering built in wordpress taxonomies like 'post_tag', 'taxonomy', etc.
<?php
/**
* Plugin Name: Remove Builtin WP Taxonomies
*/
add_action( 'init', 'unregister_taxonomy' );
/**
* Remove built in taxonomies
* @author: Franz Josef Kaiser
*/
function unregister_taxonomy( $taxonomy )
{
global $wp_taxonomies;
foreach ( wp_list_pluck( $wp_taxonomies, '_builtin' ) ) as $tax => $data )
{
// 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 ] );
}
}
}
add_action( 'wp_footer', 'check_unset_category', 999 );
function check_unset_category()
{
defined( 'WP_DEBUG' )
AND WP_DEBUG
AND printf( '<pre>%s</pre>', $GLOBALS['wp_taxonomies'] );
}
@baerkins
Copy link

You're foreach loop has an extra ) in it:

foreach ( wp_list_pluck( $wp_taxonomies, '_builtin' ) ) as $tax => $data )

Should be:

foreach ( wp_list_pluck( $wp_taxonomies, '_builtin' )  as $tax => $data )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment