Wordpress:在主题激活时删除'uncategorized'

时间:2013-11-24 01:04:37

标签: wordpress function categories

有没有办法在激活我的主题后删除默认的“未分类”类别(来自Wordpress管理员中的类别)?

这显然必须在functions.php中进行。

3 个答案:

答案 0 :(得分:3)

只要您至少有一个其他类别设置为默认类别,您就应该可以转到设置>>写入并将默认帖子类别更改为您的其他类别之一。执行此操作后,您应该可以通过转到帖子>>类别并删除它来删除未分类。

您还可以通过将其添加到functions.php:

来更改未分类的默认类别
// Uncategorized ID is always 1
wp_update_term(1, 'category', array(
    'name' => 'hello',
    'slug' => 'hello', 
    'description' => 'hi'
));

如此帖所示:https://wordpress.stackexchange.com/questions/83415/remove-rename-uncategorized-category-in-wordpress

More info on wp_update_term

答案 1 :(得分:0)

您可以使用wp_delete_category函数

<?php wp_delete_category( $cat_ID ) ?>

但是你在WordPress中至少需要一个类别,所以只要你手头创建额外的类别就可以了。

wp_delete_category参考页: http://codex.wordpress.org/Function_Reference/wp_delete_category

答案 2 :(得分:0)

这对我有用

add_filter( 'woocommerce_product_categories_widget_args', 'remove_uncategorized_category' );
add_filter( 'woocommerce_product_subcategories_args', 'remove_uncategorized_category' );

function remove_uncategorized_category( $args ) {
  $uncategorized = get_option( 'default_product_cat' );
  $args['exclude'] = $uncategorized;
  return $args;
}