WordPress 网站开发实战分享

围绕 WordPress 网站开发、功能扩展与内容运营,输出可落地的建站方法,适合企业官网、外贸独立站与长期运营型网站。

Wordpress WooCommerce产品标题重复提醒

在运营大型WooCommerce商城时,我们经常会遇到产品标题重复的问题。重复的产品标题不仅影响用户体验,还会对SEO产生负面影响,导致搜索引擎难以区分相似产品,降低页面排名。

重复标题可能带来的问题

  1. SEO负面影响:搜索引擎会认为内容是重复的,降低页面权重

  2. 用户体验差:客户难以区分相似产品

  3. 管理困难:管理员难以快速定位特定产品

  4. 数据混乱:可能导致订单处理错误

解决方案

我将提供一个完整的代码解决方案,用于检测和提醒WooCommerce产品标题重复问题。

 


// -------------------------
// WooCommerce 产品标题实时查重提示(右侧红字显示)
// -------------------------
add_action('admin_footer-post-new.php', 'realtime_product_title_check_side_notice');
add_action('admin_footer-post.php', 'realtime_product_title_check_side_notice');

function realtime_product_title_check_side_notice() {
    $screen = get_current_screen();
    if ($screen->post_type !== 'product') return;
    ?>
    <style>
        #title-duplicate-notice {
            display: inline-block;
            margin-left: 12px;
            font-weight: 500;
        }
    </style>
    <script>
    jQuery(function($) {
        let timer;
        const titleField = $('#title');
        const postID = $('#post_ID');
        const noticeID = 'title-duplicate-notice';

        if (!$('#' + noticeID).length) {
            titleField.after('<span id="' + noticeID + '"></span>');
        }

        titleField.on('input', function() {
            clearTimeout(timer);
            const title = $(this).val().trim();
            if (title.length < 2) return;

            timer = setTimeout(function() {
                $.post(ajaxurl, {
                    action: 'check_product_title_duplicate',
                    title,
                    post_id: postID.val()
                }, function(res) {
                    $('#' + noticeID).html(
                        res.exists
                        ? '<span style="color:#d63638;">⚠️ 标题已存在</span>'
                        : '<span style="color:#46b450;">✓ 可用</span>'
                    );
                }, 'json');
            }, 400);
        });
    });
    </script>
    <?php
}

最新文章

目录大纲

Scroll to Top
温馨提示:为了更好地为您提供服务,建议您添加我们的微信或留下您的微信联系方式,感谢您的支持!

扫一扫 添加商务微信

+133 3643 8551(V同步)