在WordPress中,WooCommerce会自动使自定义分类法的SLUG倍增。这就是为什么您在Live站点和本地product_brand(单数)上看到product_brands(复数)的原因。 WooCommerce使用默认情况下与产品相关的分类法使用复数sl。 如何确保一致性(单数或复数) WooCommerce的默认行为:默认情况下,WooCommerce使用诸如product_brands,product_categories等分类法的复数名称。 使用单数slug:如果您想制作分类法单数并避免复数形式,则需要修改分类法的注册。您可以通过挂接Init Action并用所需的slug进行注册。
function change_product_brand_taxonomy_slug() {
unregister_taxonomy('product_brand');
register_taxonomy('product_brand', 'product', array(
'labels' => array(
'name' => 'Product Brands',
'singular_name' => 'Product Brand',
),
'rewrite' => array(
'slug' => 'product_brand',
),
'hierarchical' => true,
));
}
add_action('init', 'change_product_brand_taxonomy_slug');