You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求编写Woocommerce函数移除产品标签URL中的product-tag

移除WooCommerce产品标签URL中的"product-tag"字符串

可以通过自定义函数修改WordPress分类法重写规则实现,无需安装插件。将以下代码添加到你的主题(或子主题)的functions.php文件中:

add_filter( 'register_taxonomy_args', 'custom_remove_product_tag_slug', 10, 3 );
function custom_remove_product_tag_slug( $args, $taxonomy, $object_type ) {
    if ( 'product_tag' === $taxonomy ) {
        $args['rewrite'] = array(
            'slug' => '',
            'with_front' => false,
            'hierarchical' => false,
        );
    }
    return $args;
}

关键操作:添加代码后必须刷新固定链接

  1. 登录WordPress后台,进入「设置」→「固定链接」页面
  2. 无需修改任何选项,直接点击「保存更改」按钮,强制更新WordPress重写规则,确保新URL结构生效

注意事项

  • 优先使用子主题添加代码,避免主题更新时丢失自定义修改
  • 若之前测试过其他相关代码,请先移除,防止规则冲突
  • 若出现404错误,再次刷新固定链接即可;仍有问题的话,检查是否有SEO插件或其他自定义重写规则干扰

内容的提问来源于stack exchange,提问作者ispreadtoyou

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 12:52:17