Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/7e191bef762cb6693ae8493e512b1d13 to your computer and use it in GitHub Desktop.
Save cameronjonesweb/7e191bef762cb6693ae8493e512b1d13 to your computer and use it in GitHub Desktop.
<?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