HUSKY - WooCommerce Products Filter Professional

Insert [script type=”application/ld+json”] script into SEO URL requests

Here is ticket about the issue: https://pluginus.net/support/topic/seo-url-request-no-support-for-wpbakery-or-json-ld-schema-markup – problem that it is not possible directly insert any scripts into SEO Rules as all tags are filtered thanks to striptags functionality and its really useful for site safety. So way here is using next code in file 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);

What is need: is to insert into SEO text window arbitrary keys to let the script insert right json-ld code https://share.pluginus.net/image/i20251104122715.png

 


Troubles? Ask for Support!