category page with snippet data and “offer”

#835555
  • Resolved Alireza
    Rank Math free

    Hi! I have a category page with products in it. I have submitted it to google search console and received the error “Either ‘offers’, ‘review’ or ‘aggregateRating’ should be specified”. Your colleague told me to Remove Snippet Data for my category pages. But now after 2 months of submitting the page without the snippet data, I believe my page is not properly indexed by google. Now, I’d like to add the snippet data with “offer” to my category pages. Can you please advise on how to proceed?

Viewing 15 replies - 1 through 15 (of 23 total)
  • Hello,

    I apologize for the inconvenience you’ve faced with your category page indexing. To add the necessary Schema data, including the "offer" field, to your category pages in Rank Math, you can follow these steps:

    1. Navigate to Rank Math SEO → Titles & Meta → Product Categories in your WordPress dashboard.
    2. Scroll down to the product category tab and locate the Remove Snippet Data option.
    3. Turn off the Remove Snippet Data option to enable the Schema data for your category pages.

    Here is a visual guide to help you locate and adjust the settings:

    Remove snippet data from product categories

    By following these steps, you can add the necessary Schema data, including the "offer" field, to your category pages. This should help resolve the error you received in Google Search Console.

    If you encounter any issues or need further assistance, please feel free to reach out. We’re here to help!

    Best regards.

    Sources:
    Google Search Console Missing Field Warning » Rank Math
    Remove All Schema from Product Category Pages » Rank Math
    How to Optimize a Category Page » Rank Math

    Alireza
    Rank Math free

    Your solution does not add ‘offer’ to my schema.

    Hello,

    Thank you for contacting support.

    You cannot add the Product Schema to category pages because that is only designed for singular product pages or archive pages with a single product, which is not the case here.

    That is the only way to comply with the Google guidelines for this type of Schema markup.

    Don’t hesitate to get in touch if you have any other questions.

    Alireza
    Rank Math free

    Hi,

    Thanks for the reply.

    So, my questions becomes: why doesn’t it comply with google guidelines when Snippet Data is added? Why do you provide the Snippet Data option if it causes error for google?

    And how can I make sure that google correctly identifies every individual item in my category e-commerce page?

    Hello,

    The Schema option is available on the category pages to allow users to add other Schema types to the category pages in case they add additional content. If your category pages only display the collection of the products then you don’t need to add any Schema type. Our plugin automatically adds the CollectionPage Schema to categories, and Google will be able to detect all the products on the page.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Alireza
    Rank Math free

    Okay thanks. However, I read in this article that itemlist can help google detect products in a category page. Can I add that to my category pages?

    Hello,

    The Free plugin doesn’t have the option to add Schema on the category pages. However, you can use the following filter to add the itemList Schema to the product categories:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	if(is_product_category()) {
    		$products = get_posts( array(
      'post_type' => 'product',
      'numberposts' => -1,
      'post_status' => 'publish',
      'fields' => 'ids',
      'tax_query' => array(
         array(
            'taxonomy' => 'product_cat',
            'field' => 'id',
            'terms' => get_queried_object_id(),
            )
         ),
      ));
    		$data['itemList']['itemListElement'] = [];
    	foreach($products as $key => $product) {
    		$url = get_the_permalink($product);
    		$schema[] = ["@type"=> "ListItem",
      				   "position"=> $key,
    				   "url"=> $url
    	  			  ];
    		$data['itemList']['@type'] = 'itemList';
    		$data['itemList']['itemListElement'] = $schema;
    	}
    	}
    	return $data;
    }, 99, 2);

    Here is how to add a filter to your site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Alireza
    Rank Math free

    Thanks! I added your code to my functions.php, and indeed I see listitem schema when I activate Snippet Data. Could you also help me add ‘offer’ and ‘color’ to my products? I have a color attribute, but I’m talking about color as a property of product (https://schema.org/Product).

    Hello,

    To add the ‘offer’ and ‘color’ properties to your product schema within the itemList, you need to enhance the schema data with additional product details.

    Here’s the modified code to include offer and color properties:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	if(is_product_category()) {
    		$products = get_posts( array(
    			'post_type' => 'product',
    			'numberposts' => -1,
    			'post_status' => 'publish',
    			'fields' => 'ids',
    			'tax_query' => array(
    				array(
    					'taxonomy' => 'product_cat',
    					'field' => 'id',
    					'terms' => get_queried_object_id(),
    				)
    			),
    		));
    
    		$data['itemList']['itemListElement'] = [];
    
    		foreach($products as $key => $product) {
    			$product_obj = wc_get_product($product);
    			$url = get_the_permalink($product);
    			$price = $product_obj->get_price();
    			$currency = get_woocommerce_currency();
    			$availability = $product_obj->is_in_stock() ? 'InStock' : 'OutOfStock';
    			$colors = wc_get_product_terms( $product, 'pa_color', array( 'fields' => 'names' ) );
    
    			$schema[] = [
    				"@type" => "ListItem",
    				"position" => $key,
    				"url" => $url,
    				"item" => [
    					"@type" => "Product",
    					"name" => get_the_title($product),
    					"offers" => [
    						"@type" => "Offer",
    						"priceCurrency" => $currency,
    						"price" => $price,
    						"availability" => "http://schema.org/" . $availability,
    					],
    					"color" => implode(', ', $colors)
    				]
    			];
    		}
    
    		$data['itemList']['@type'] = 'ItemList';
    		$data['itemList']['itemListElement'] = $schema;
    	}
    	return $data;
    }, 99, 2);

    Let us know how it goes. We look forward to hearing from you.

    Thank you.

    Alireza
    Rank Math free

    Hi, Thank you so much! I just want to make sure that the ‘color’ and ‘offer’ are inside the product snippet. I see that you’ve added it inside ListItem. Can you please edit that?

    Alireza
    Rank Math free

    My bad, I see offer and color are inside the product snippet. However, it doesn’t work. Neither ‘offer’, nor ‘color’ appear in the schema output.

    Hello,

    Please disregard the last piece of code shared as that does not comply with Google guidelines because it adds multiple Product Schemas to the category pages.

    The ItemList Schema can be added to the product category pages but that type of Schema doesn’t include support for the properties offer or any other properties designed for products so you cannot add them and still get compliant Schema markup.

    If you want the ItemList Schema you can use the code we shared here: https://support.rankmath.com/ticket/category-page-with-snippet-data-and-offer/?view=all#post-835979

    However, you cannot add properties of the Product Schema to that markup.

    Don’t hesitate to get in touch if you have any other questions.

    Alireza
    Rank Math free

    Okay, but that code doesn’t have offer and color. Can you please help me add those to product schema?

    Alireza
    Rank Math free

    So, finally the code that Adetayo gave me is working. It took some time for it to take effect. I’m very grateful for your help Adetayo!

    Would you mind helping me do the same for my product colour attribute pages? I have gathered all products by their colour in their attribute page like mysite.com/colour/white. It’s a CollectionPage type. I’d like to add an itemListElement that goes like this for each item.

    {"@type":"ListItem","position":"0","url":"https://mysite.com/product/product-name/","item":{"@type":"Product","name":"product name","offers":{"@type":"Offer","priceCurrency":"EUR","price":"100","availability":"http://schema.org/InStock"},"color":"White"}}

    Hello,

    You can use the following filter to add the item details to the itemList Schema:

    add_filter( 'rank_math/json_ld', function( $data, $jsonld ) {
    	if(is_product_category()) {
    		$products = get_posts( array(
      'post_type' => 'product',
      'numberposts' => -1,
      'post_status' => 'publish',
      'fields' => 'ids',
      'tax_query' => array(
         array(
            'taxonomy' => 'product_cat',
            'field' => 'id',
            'terms' => get_queried_object_id(),
            )
         ),
      ));
    		$data['itemList']['itemListElement'] = [];
    	foreach($products as $key => $product) {
    		$url = get_the_permalink($product);
    		$schema[] = ["@type"=> "ListItem",
      				   "position"=> $key,
    				   "url"=> $url,
    					 "item" => [
    						 "@type" => "Product",
    						 "name" => get_the_title($product),
    						 "offers" => [
    							 "@type" => "offer",
    							 "priceCurrency" => "EUR",
    							 "price" => wc_get_product($product)->get_price()
    							 
    						 ],
    						 "color" => wc_get_product($product)->get_attribute('pa_color')
    					 ]
    	  			  ];
    		$data['itemList']['@type'] = 'itemList';
    		$data['itemList']['itemListElement'] = $schema;
    	}
    	}
    	return $data;
    }, 99, 2);

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 15 replies - 1 through 15 (of 23 total)

The ticket ‘category page with snippet data and “offer”’ is closed to new replies.