Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Delete the option setting for the default category
*
* @link https://cameronjonesweb.com.au/blog/how-to-remove-the-uncategorised-category-from-wordpress-and-woocommerce
*/
function cameronjonesweb_delete_default_category_option() {
if ( get_option( 'default_category' ) ) {
delete_option( 'default_category' );
}
}
add_action( 'init', 'cameronjonesweb_delete_default_category_option' );
<?php
/**
* Remove default terms from categories
*
* @link https://cameronjonesweb.com.au/blog/how-to-remove-the-uncategorised-category-from-wordpress-and-woocommerce
*
* @param array $args Array of arguments for registering a taxonomy.
* @param string $taxonomy Taxonomy key.
* @param array $object_type Array of names of object types for the taxonomy.
*/
function cameronjonesweb_filter_taxonomy_args( $args, $taxonomy, $object_type ) {
if ( 'category' === $taxonomy ) {
$args['default_term'] = false;
}
return $args;
}
add_filter( 'register_taxonomy_args', 'cameronjonesweb_filter_taxonomy_args', 10, 3 );
<?php
/**
* Remove default terms from categories
*
* @link https://cameronjonesweb.com.au/blog/how-to-remove-the-uncategorised-category-from-wordpress-and-woocommerce
*
* @param array $args Array of arguments for registering a taxonomy.
* @param string $taxonomy Taxonomy key.
* @param array $object_type Array of names of object types for the taxonomy.
*/
function cameronjonesweb_filter_taxonomy_args( $args, $taxonomy, $object_type ) {
if ( 'category' === $taxonomy || 'product_cat' === $taxonomy ) {
$args['default_term'] = false;
}
return $args;
}
add_filter( 'register_taxonomy_args', 'cameronjonesweb_filter_taxonomy_args', 10, 3 );
/**
* Delete the option setting for the default category
*/
function cameronjonesweb_delete_default_category_option() {
if ( get_option( 'default_category' ) ) {
delete_option( 'default_category' );
}
if ( get_option( 'default_product_cat' ) ) {
delete_option( 'default_product_cat' );
}
}
add_action( 'init', 'cameronjonesweb_delete_default_category_option' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment