dalewoods007 Posted December 28, 2018 Report Share Posted December 28, 2018 Hey guys I want to filter the JSON-LD product schema before it is outputted. I was able to do this with the Woo Commerce filter add_filter( 'woocommerce_structured_data_product', ... The schema theme is using the Rank Math schema builder. I tried to track down where the code is being generated and I found this. /** * JSON LD output function that the functions for specific code can hook into. */ public function json_ld() { /** * Collect data to output in JSON-LD. * * @param array $unsigned An array of data to output in json-ld. * @param JsonLD $unsigned JsonLD instance. */ $data = $this->do_filter( 'json_ld', array(), $this ); if ( is_array( $data ) && ! empty( $data ) ) { echo '<script type="application/ld+json">' . wp_json_encode( array_values( array_filter( $data ) ) ) . '</script>' . "\n"; } } There is this line $data = $this->do_filter( 'json_ld', array(), $this ); Which I traced back should translate into a wordpress filter called like this... add_filter( 'rank_math/json_ld', function($data) { print_r($data); }); Only an empty array is pushed through this filter hook, and that makes sense because only an empty array is passed through that do_filter rank math method. What is the correct way to filter this so I can add on to the JSON-LD data... I want to add brand, and some other pieces that the google schema checker is whining about. Link to comment Share on other sites More sharing options...
Support Pratik.d Posted December 28, 2018 Support Report Share Posted December 28, 2018 Hello, Thank you for contacting MyThemeShop today. You can use rank_math/snippet/rich_snippet_product_entity filter to change the product snippet data. add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $pre ) { // You can modify/add product details here by extending the $pre variable return $pre; }); Hope that helps. If there is anything else, please let us know. Thank you. 🏁Rank #1 on Google With our WordPress SEO Plugin. ⚡Score a 💯on PageSpeed and Dominate Search Rankings. ✏ Editing theme files? Please create a child theme to make your changes update-proof. Link to comment Share on other sites More sharing options...
Recommended Posts