Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active August 18, 2021 13:18
Show Gist options
  • Save obiPlabon/382b97935c107622a8db2a31f7d874a3 to your computer and use it in GitHub Desktop.
Save obiPlabon/382b97935c107622a8db2a31f7d874a3 to your computer and use it in GitHub Desktop.
Add RankMath ratingValue schema support to Directorist
<?php
add_filter( 'rank_math/json_ld', function( $schemas, $jsonld ) {
if ( ! ( defined( 'ATBDP_POST_TYPE' ) && is_singular( ATBDP_POST_TYPE ) ) ) {
return $schemas;
}
foreach ( $schemas as $key => &$schema ) {
if ( is_array( $schema['@type'] ) ) {
continue;
}
$type = strtolower( $schema['@type'] );
// You can more support extending the array
if ( ! in_array( $type, array( 'product' ), true ) ) {
continue;
}
if ( isset( $schema['review'], $schema['review']['reviewRating'] ) ) {
$schema['review']['reviewRating'] = array_merge(
$schema['review']['reviewRating'],
array(
'ratingValue' => ATBDP()->review->get_average( get_the_ID() )
)
);
}
}
return $schemas;
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment