Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Last active June 21, 2019 21:44
Show Gist options
  • Select an option

  • Save franz-josef-kaiser/870890 to your computer and use it in GitHub Desktop.

Select an option

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'] );
}
@AllanVSQZ
Copy link
Copy Markdown

Hola, lo siento pero no me funcionó, quizá hice algo malo, de todas formas te dejo aquí un código que si me sirvió en WP4.4.
Saludos

    add_action( 'init', 'unregister_taxonomy' );
    function unregister_taxonomy()
    {
        global $wp_taxonomies;
        $taxonomy = 'taxonomy_to_remove';
        if ( taxonomy_exists($taxonomy) )
        unset( $wp_taxonomies[$taxonomy] );
    }

@baerkins
Copy link
Copy Markdown

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