PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

“SEO URL request” – No support for WPBakery or JSON-LD schema markup

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.
12

Hello Bulli

You not undertood me. Please use keys here https://share.pluginus.net/image/i20251103142130.png - BUT the code write in functions.php. That keys are just short string to let the script know what ld-json to type. Here is result: https://share.pluginus.net/image/i20251104122504.png

Place this code into functions.php file:

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 'sh1':

$txt='<script type="application/ld+json">
{
"@context":"https://schema.org",
"@graph": [
{
...
}
]
}
</script>';

break;

default:
break;
}

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

 

Use only keys here https://share.pluginus.net/image/i20251104122715.png - ONLY KEYS, let the code will be placed in file.functions.php file as admitted above

Hello,

thank you for the code.
Is there maybe an option to store the schema files in a separate /schema/ folder and load them from there — for example as sh1.json, where the JSON-LD code is included inside each file?

That would make management and maintenance much easier.

Thank you very much for your support! 🙏

Hello Bulli

Yes, it is possible, here is the code:

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;
        }
        $sh_key = apply_filters('woof_seo_text', $url_request->seo->replace_vars($rule['text'], $url_request->seo->get_current_replace_vars()));
        if (!empty($sh_key)) {
            // Path to JSON-LD schemas folder
            $upload_dir = wp_upload_dir();
            $schemas_dir = $upload_dir['basedir'] . '/json-ld-schemas/';
            $schema_file = $schemas_dir . $sh_key . '.json';
            // Check if file exists and read it
            if (file_exists($schema_file)) {
                $txt = file_get_contents($schema_file);
echo '<div class="woof_seo_text"><script type="application/ld+json">' . $txt ."</script></div>\r\n";
            }
        }
    }, 99999);
}, 1);
You need to create in folder wp-upload new folder 'json-ld-schemas' - and place your json files with names the same as keys in HUSKY admin you use for shemas, for example key1.json, and you can place in that file code like:
{ "@context": "https://schema.org", "@graph": [ { ... } ] } - you see, clean json only, but this way is good if you have static jsons, if you need dynamic information for ld-json:

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;
        }
        $sh_key = apply_filters('woof_seo_text', $url_request->seo->replace_vars($rule['text'], $url_request->seo->get_current_replace_vars()));
        if (!empty($sh_key)) {
            // Path to JSON-LD schemas folder
            $upload_dir = wp_upload_dir();
            $schemas_dir = $upload_dir['basedir'] . '/json-ld-schemas/';
            $schema_file = $schemas_dir . $sh_key . '.json';
            // Check if file exists and read it
            if (file_exists($schema_file)) {
                $txt = file_get_contents($schema_file);
echo '<div class="woof_seo_text"><script type="application/ld+json">' . $txt ."</script></div>\r\n";
            }
        }
    }, 99999);
}, 1);

as an example create file /wp-content/uploads/json-ld-schemas/sh1.php:

<?php
// sh1.php - Dynamic JSON-LD for product category

global $wp_query;

$term = get_queried_object();
$category_name = $term ? $term->name : 'Products';
$category_url = get_term_link($term);

$json = array(
'@context' => 'https://schema.org',
'@type' => 'CollectionPage',
'name' => $category_name,
'url' => $category_url,
'description' => term_description($term->term_id),
'breadcrumb' => array(
'@type' => 'BreadcrumbList',
'itemListElement' => array(
array(
'@type' => 'ListItem',
'position' => 1,
'name' => 'Home',
'item' => home_url()
),
array(
'@type' => 'ListItem',
'position' => 2,
'name' => $category_name,
'item' => $category_url
)
)
)
);

echo json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

I hope you undertood both ideas

Welcome!

Hello Alex,

thank you very much for your help and the code example.

One small issue remains:
the JSON key (for example key_action1) is still displayed at the top of the frontend.
So the file is not being loaded, and the key itself appears as plain text.

Could you please help me with this?

Thanks again for your time and support!

12