Limitations of Rank Math Structured Data Filter – Please Update It

  • I am using this filter to add brand data to my product schema.

    It’s fine on single product pages, but I can’t get this to work on product category pages.

    Currently the signature looks like:

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function($markup) );

    Can you please pass the product obj also, like the original Woo Commerce filter does…

    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function($markup, $product) );

    That way on a category page, we can update the schema for all the products listed.

    If there is any other way to filter the schema on product cat pages let me know, because I am really stuck here atm.

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

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Please add below filter code in your theme’s functions.php file to add brand valud on Product archive pages:

    
    add_action( 'rank_math/json_ld', function( $data, $json_ld ) {
    	if ( isset( $data['ProductsPage'] ) ) {
    		foreach ( $data['ProductsPage']['@graph'] as $key => $product ) {
    			$data['ProductsPage']['@graph'][$key]['brand'] = 'Test Brand';
    		}
    	}
    	return $data;
    }, 15, 2 );
    

    Although as per the Google norms you should only include the data in snippet which exists on the page:

    The structured data on the page should describe the content of that page. You should not create blank or empty pages just to hold structured data; nor should you add structured data about information that is not visible to the user, even if the information is accurate.

    So instead of adding brand value to Products on archive pages I would suggest you to remove the Product snippet from arhcive pages since it is irrelevant and not needed. In the upcoming update of the Plugin, we’ve added an option in Settings to remove Prdouct snippet from archive pages as it is recommended by Google not having Product snippet on archive pages. For now, you can use below filter code to remove the Product snippet from archive pages:

    
    add_action( 'rank_math/json_ld', function( $data, $json_ld ) {
    	if ( isset( $data['ProductsPage'] ) ) {
    		unset( $data['ProductsPage'] );
    	}
    	return $data;
    }, 15, 2 );
    

    Hope that helps. Thank you.

    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.

    hi,

    Is there anyway to replace some of generated attribute data in json+ld data.
    Let me know.

    Hello,

    Thank you for contacting Rank Math today.

    Yes this is possible, you can use the following filter to modify posts schema data:

    /**
     * Filter to Short-circuit Schema if a 3rd party is interested in generating their own data.
     * Replace $schmea_type with schema name like article, review, etc.
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( "rank_math/snippet/rich_snippet_{$schema_type}", function( $entity ) {
     return $entity;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this ticket.