I’m sure you want to use the_content
filter instead of the default_content
filter (already mentioned by @jgraup) because what happens if the generated HTML changes? Then you’re stuck with it in your content. It’s better to add it dynamically. Here’s one suggestion:
add_filter( 'the_content', function( $content)
{
if( ! in_the_loop() )
return $content;
if( 'property' !== get_post_type() )
return $content;
$args = [
'rating_item_ids' => 2,
'show_count' => false,
'result_type' => 'value_rt',
'no_rating_results_text' => 'Not Rated',
'echo' => 0,
];
if ( class_exists( 'MRP_Multi_Rating_API' ) )
{
$content .= MRP_Multi_Rating_API::display_rating_result( $args );
// Modify arguments for the second run
$args['rating_item_ids'] = 5;
$args['result_type'] = 'overall_rt';
$content .= MRP_Multi_Rating_API::display_rating_result( $args );
}
return $content;
} );
Notice that we use the in_the_loop
check (here I link to the question by @PieterGoosen and the answer by @gmazzap), because I assume you don’t want this added to every content part of your site.
You also don’t need to check twice for the existince of the same class.
Note that this has one big assumption, namely the echo
attribute 😉