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

寻求移除WooCommerce后台产品编辑页面指定提示文本的代码片段

移除WooCommerce后台产品编辑页的图片上传提示文本

要移除产品编辑页面中“Upload jpeg files that are 1000 x 1000 pixels or larger (max. 50 mb)”这段提示文本,可通过后台自定义CSS的方式实现,目标元素类名为.image-added-detail,以下是两种可行方案:

方案1:内联CSS(无需额外文件)

将以下代码添加到主题(或子主题)的functions.php文件中,仅在产品编辑页面加载隐藏样式:

/**
 * 隐藏WooCommerce产品编辑页的图片尺寸提示文本
 */
function remove_product_image_upload_notice() {
    $current_screen = get_current_screen();
    // 仅在产品编辑页面生效
    if ( $current_screen && 'product' === $current_screen->post_type && 'post' === $current_screen->base ) {
        echo '<style>
            .post-type-product .image-added-detail {
                display: none !important;
            }
        </style>';
    }
}
add_action( 'admin_head', 'remove_product_image_upload_notice' );

方案2:独立CSS文件(更易维护)

  1. 在主题目录下新建css/admin-product-styles.css文件,写入以下CSS:
/* 移除WooCommerce产品编辑页的图片上传提示 */
.post-type-product .image-added-detail {
    display: none !important;
}
  1. 将以下代码添加到functions.php中,确保样式仅在产品编辑页加载:
/**
 * 注册并加载产品编辑页的自定义后台样式
 */
function enqueue_custom_admin_product_styles() {
    $current_screen = get_current_screen();
    if ( $current_screen && 'product' === $current_screen->post_type && 'post' === $current_screen->base ) {
        wp_enqueue_style(
            'custom-admin-product-styles',
            get_stylesheet_directory_uri() . '/css/admin-product-styles.css',
            array(),
            wp_get_theme()->get('Version')
        );
    }
}
add_action( 'admin_enqueue_scripts', 'enqueue_custom_admin_product_styles' );

注意事项

  • 优先使用子主题修改,避免主题更新导致代码丢失;
  • 若样式未生效,可增加选择器优先级(比如前缀body:body.post-type-product .image-added-detail);
  • 修改前备份主题文件,防止操作失误导致后台异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 12:25:30