Default Rich Snippet for Post Types

#689
  • Resolved Trip24 Vn
    Rank Math free

    Hello,
    I have set Rich Snippet Type for my Post types
    However, I want to set default rich snippet for each post types on rank-math-options-titles
    Example: all of the below fields will display on option titles to set default, because woo or acf had filled fields, I just set %customfield(field-name)%

    Rich Snippet Type 
    Headline
    Description
    Product SKU
    Product Brand
    Product Currency
    ISO 4217 Currency Code

    thank you

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

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

    Rank Math plugin doesn’t have any option to change the fields in Post Settings. Although you can use plugin filter to add/change the values on frontend added in ld+json. Below is an example filter code to change the snippet values:

    
    add_filter( "rank_math/json_ld", function( $data, $jsonld ) {
      if ( ! is_single() ) {
        return $data;
      }
    	
    	$post_type  = $jsonld->post->post_type;
    	$product_id = $jsonld->post_id;
    
    	unset( $data['richSnippet'] );
    	// Use get_post_meta( $product_id, '_meta_key', true ); to get the meta value
    	$data['richSnippet'] = array(
    	 '@context' => 'https://schema.org',
    	 '@type' => 'Product',
    	 'name' => $jsonld->parts['title'],
    	 'description' => $jsonld->parts['desc'],
    	 'url' => $jsonld->parts['url'],
    	 'sku' => get_post_meta( $product_id, '_meta_key', true ),
    	 'brand' => array(
    	     '@type' => 'Thing',
    	     'name'  => get_post_meta( $product_id, '_brand_meta_key', true ),
    	 ),
    	 'offers' => array(
     			'@type'         => 'Offer',
     			'priceCurrency' => get_post_meta( $product_id, '_currency_meta_key', true ),
       		'price'         => get_post_meta( $product_id, '_price_meta_key', true ),
    	 )
    	);
    	return $data;
    }, 20, 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.

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

You must be logged in to reply to this ticket.