HUSKY - Product Filter for WooCommerce

将脚本插入 HUSKY SEO URL 请求(JSON-LD 变通方法)

这是关于该问题的工单:https://pluginus.net/support/topic/seo-url-request-no-support-for-wpbakery-or-json-ld-schema-markup – 问题在于无法直接将任何脚本插入SEO规则,因为striptags功能会过滤所有标签,这对网站安全非常有用。因此,这里的方法是在functions.php文件中使用以下代码:

add_action('init', function () {
    $url_request = WOOF_EXT::$includes['applications']['url_request'];
    remove_filter('woocommerce_after_shop_loop', array($url_request->seo, 'add_seo_text'), 99999);

    add_filter('woocommerce_after_shop_loop', function () use ($url_request) {
        $rule = $url_request->seo->check_search_rules();
        if (!isset($rule['text']) || !$url_request->seo->do_index()) {
            return;
        }

        $txt = apply_filters('woof_seo_text', $url_request->seo->replace_vars($rule['text'], $url_request->seo->get_current_replace_vars()));

        if (!empty($txt)) {

            switch ($txt) {
                case 'key1':
                    $txt = '<script type="application/ld+json">... place your schema here ...</script>';
                    break;
                case 'key2':
                    $txt = '<script type="application/ld+json">... place your schema here ...</script>';
                    break;

                default:
                    break;
            }

            echo '<div class="woof_seo_text">' . $txt . "</div>\r\n";
        }
    }, 99999);
}, 1);

需要做的是:在SEO文本窗口中插入任意键,以便脚本插入正确的json-ld代码 https://share.pluginus.net/image/i20251104122715.png