Title: Exclude code in Posts
Last modified: October 16, 2020

---

# Exclude code in Posts

 *  Resolved [ffranciscocasas](https://wordpress.org/support/users/ffranciscocasas/)
 * (@ffranciscocasas)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/exclude-code-in-posts/)
 * 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 [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/exclude-code-in-posts/#post-13731722)
 * Hi [@ffranciscocasas](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/exclude-code-in-posts/#post-13731722)
 * Status: resolved