Home / Disable / Remove “No Reviews” label if there are not reviews in Tasty Recipes
Duplicate Snippet

Embed Snippet on Your Site

Remove “No Reviews” label if there are not reviews in Tasty Recipes

Remove "No Reviews" label if there are not reviews in Tasty Recipes

<10
Code Preview
php
<?php
function tasty_recipes_remove_no_reviews_label( $content ) {
    global $post;
    if ( ! $post ) {
        return $content;
    }
    $post_id    = $post->ID;
    $has_recipe = \Tasty_Recipes::has_recipe( $post_id );
    if ( ! $has_recipe ) {
        return $content;
    }
    $recipe_id = \Tasty_Recipes::get_recipe_ids_for_post( $post_id )[0];
    $recipe    = \Tasty_Recipes\Objects\Recipe::get_by_id( $recipe_id );
    if ( ! $recipe || $recipe->get_total_reviews() ) {
        return $content;
    }
    $pattern = '/<p[^>]*>\s*<span[^>]*class=["\']?rating-label["\']?[^>]*>.*?<\/span>\s*<\/p>/is';
    $content = preg_replace( $pattern, '', $content );
    return $content;
}
add_filter( 'the_content', 'tasty_recipes_remove_no_reviews_label' );

Comments

Add a Comment