/**
 * Inject CollectionPage Schema for WooCommerce Shop & Product Category Archives
 * Deploy via Code Snippets or child theme functions.php
 */
add_filter('rank_math/json_ld', function($data){
    // Skip admin backend & pagination pages
    if (is_admin() || get_query_var('paged') > 1) {
        return $data;
    }
    // 防护：避免Woo未加载引发函数不存在致命报错
    if (!function_exists('wc_get_page_permalink')) {
        return $data;
    }
    $shop_url = wc_get_page_permalink('shop');

    // Add CollectionPage for main shop page
    if (is_shop()) {
        // 检测是否已存在CollectionPage，防止重复输出
        foreach ($data as $item) {
            if (isset($item['@type']) && $item['@type'] === 'CollectionPage') {
                return $data;
            }
        }

        $data[] = [
            '@type' => 'CollectionPage',
            '@id' => $shop_url . '#collectionpage',
            'url' => $shop_url,
            'name' => wp_strip_all_tags(wp_get_document_title()),
            'description' => 'Explore Gorvey designer lighting collections featuring luxury chandeliers, pendant lights, ceiling fixtures and decorative lighting solutions for residential and commercial spaces.',
            'isPartOf' => [
                '@type' => 'WebSite',
                '@id' => home_url('/') . '#website'
            ]
        ];
    }

    // Convert default WebPage schema to CollectionPage for product categories
    if (is_product_category()) {
        foreach ($data as $key => $schema_item) {
            if (isset($schema_item['@type']) && $schema_item['@type'] === 'WebPage') {
                $data[$key]['@type'] = 'CollectionPage';
                $data[$key]['name'] = wp_strip_all_tags(wp_get_document_title());
            }
        }
    }
    return $data;
}, 99);

/**
 * Add ItemList markup for product category archive pages
 * Limit maximum 24 items to prevent oversized JSON-LD
 * Add get_term_link error protection to avoid broken @id
 */
add_filter('rank_math/json_ld',function($data){
    // Skip admin, pagination, non-category pages
    if(is_admin() || get_query_var('paged') > 1 || !is_product_category()){
        return $data;
    }
    $category_obj = get_queried_object();
    global $wp_query;

    if( empty($wp_query->posts) ) {
        return $data;
    }

    // 容错：捕获get_term_link异常，杜绝WP_Error污染Schema
    $category_url = get_term_link($category_obj);
    if ( is_wp_error( $category_url ) ) {
        return $data;
    }

    $item_elements = [];
    // 最多输出24条商品，控制JSON-LD体积
    $products = array_slice($wp_query->posts, 0, 24);
    foreach ($products as $index => $product_post) {
        $item_elements[] = [
            "@type" => "ListItem",
            "position" => $index + 1,
            "name" => get_the_title($product_post->ID),
            "url" => get_permalink($product_post->ID)
        ];
    }
    $data[] = [
        "@type" => "ItemList",
        "@id" => $category_url . "#itemlist",
        "name" => $category_obj->name . " Designer Lighting Collection",
        "itemListOrder" => "https://schema.org/ItemListOrderAscending",
        "itemListElement" => $item_elements
    ];
    return $data;
},100);

/**
 * Disable WP Rocket Remote JS Proxy
 * Prevent GTM/GA scripts rewritten to /metrics/ (Fix 404 MIME error)
 */
add_filter(
    'rocket_remote_js_proxy_enabled',
    '__return_false'
);

/**
 * Force exclude Google tracking scripts from WP Rocket Delay JS
 * Double protection, avoid remote script hijack
 */
add_filter(
    'rocket_delay_js_exclusions',
    function($excluded){
        $excluded[] = 'googletagmanager.com';
        $excluded[] = 'google-analytics.com';
        $excluded[] = 'gtag';
        $excluded[] = 'G-5BZVV9BHFC';
        return $excluded;
    }
);<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//www.gorvey.com/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://www.gorvey.com/post-sitemap.xml</loc>
		<lastmod>2026-07-17T16:22:03+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/page-sitemap.xml</loc>
		<lastmod>2026-07-29T12:44:50+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/product-sitemap1.xml</loc>
		<lastmod>2026-07-30T05:07:55+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/product-sitemap2.xml</loc>
		<lastmod>2026-07-29T08:04:57+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/product-sitemap3.xml</loc>
		<lastmod>2026-07-29T08:04:57+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/product-sitemap4.xml</loc>
		<lastmod>2026-07-29T08:04:52+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/product-sitemap5.xml</loc>
		<lastmod>2026-07-29T08:04:50+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/product-sitemap6.xml</loc>
		<lastmod>2026-07-29T08:04:47+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/category-sitemap.xml</loc>
		<lastmod>2026-07-17T16:22:03+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/product_brand-sitemap.xml</loc>
		<lastmod>2026-07-30T05:07:55+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/product_cat-sitemap.xml</loc>
		<lastmod>2026-07-30T05:07:55+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/video-sitemap.xml</loc>
		<lastmod>2026-07-29T12:40:46+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.gorvey.com/local-sitemap.xml</loc>
		<lastmod>2026-07-17T06:19:38+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->