• Resolved Imageffranciscocasas

    (@ffranciscocasas)


    Hi, I dont have PHP skills and I want the following code to be exclude it on every Post or even just include in on my Home page:

    add_filter('yasr_vv_shortcode', function($shortcode_html, $stored_votes) {
        $number_of_votes = $stored_votes['number_of_votes'];
        if ($number_of_votes > 0) {
            $average_rating = $stored_votes['sum_votes']/$number_of_votes;
        } else {
            $average_rating = 0;
        }
    
    $average_rating=round($average_rating, 1);
    
    	return '<b>Rating:</b>'.$average_rating;
    }, 10, 2);
    
    add_filter('yasr_vv_txt_after', function($span_text_after_stars) {
        return false;
    }, 10, 1);
Viewing 1 replies (of 1 total)
  • Plugin Author ImageShea Bunge

    (@bungeshea)

    Hi @ffranciscocasas,

    You can add an is_home() check to the filter hooks. This function will only return true for the home page.

    add_filter( 'yasr_vv_shortcode', function ( $shortcode_html, $stored_votes ) {
    
    	if ( ! is_home() ) {
    		return $shortcode_html;
    	}
    
    	$number_of_votes = $stored_votes['number_of_votes'];
    
    	if ( $number_of_votes > 0 ) {
    		$average_rating = $stored_votes['sum_votes'] / $number_of_votes;
    	} else {
    		$average_rating = 0;
    	}
    
    	$average_rating = round( $average_rating, 1 );
    
    	return '<b>Rating:</b>' . $average_rating;
    }, 10, 2 );
    
    add_filter( 'yasr_vv_txt_after', function ( $span_text_after_stars ) {
    
    	if ( ! is_home() ) {
    		return $span_text_after_stars;
    	}
    	
    	return false;
    }, 10, 1 );
Viewing 1 replies (of 1 total)

The topic ‘Exclude code in Posts’ is closed to new replies.