Exclude blog from simple ad

Hi

I would like to exclude some blog from simple ads.
Is it possible and how ?

  • Nastia

    Hello Frédéric , I hope you are doing well today!

    It is not possible to do with the Simple Ads plugin, out of the box.

    To hide ads on selected posts, will require custom coding. I've searched and there is no ready solution on the forums. I have asked our second level support to provide you a feedback here, but this will take some time, because our developers dealing with very complex issues daily.

    If this is something you require in no time, please feel free to post a job in the Jobs & Pros section, so a skilfull developer can do this for you.

    Kind regards,
    Nastia

  • Panos

    Hi Frédéric ,

    As Nastia mentioned, it's not supported by plugin, so we need to override default behavior. Thankfully it's pretty simple in this case:slight_smile:

    Please try adding the following snipped at your child theme's functions.php :

    function wpmudev_simple_ads_output( $content ){
    
    	$no_ads_page_ids = array(1045, 1149, 1854, 3542);//<=== Edit these ids :)
    
    	global $wpdb, $simple_ads_page_ads, $current_site, $post;
    
    	if( isset( $post->ID ) && in_array( $post->ID, $no_ads_page_ids )  ) return $content;
    
    	$advertising_ads_per_page = get_site_option('advertising_ads_per_page');
    	$advertising_main_blog = get_site_option('advertising_main_blog', 'hide');
    	$display_ads = 'yes';
    
    	if ( $wpdb->blogid == $current_site->id && $advertising_main_blog == 'hide' ) {
    		$display_ads = 'no';
    	}
    	if ( $display_ads == 'yes' ) {
    		if ( is_page() ) {
    			if ( get_site_option('advertising_location_before_page_content') == '1' ) {
    				$page_ads = $simple_ads_page_ads->get_count();
    				if ( $page_ads < $advertising_ads_per_page ) {
    					$content = simple_ads_get_ad_code('before') . $content;
    					$simple_ads_page_ads->increase();
    				}
    			}
    			if ( get_site_option('advertising_location_after_page_content') == '1' ) {
    				$page_ads = $simple_ads_page_ads->get_count();
    				if ( $page_ads < $advertising_ads_per_page ) {
    					$content = $content . simple_ads_get_ad_code('after');
    					$simple_ads_page_ads->increase();
    				}
    			}
    		} else {
    			if ( get_site_option('advertising_location_before_post_content') == '1' ) {
    				$page_ads = $simple_ads_page_ads->get_count();
    				if ( $page_ads < $advertising_ads_per_page ) {
    					$content = simple_ads_get_ad_code('before') . $content;
    					$simple_ads_page_ads->increase();
    				}
    			}
    			if ( get_site_option('advertising_location_after_post_content') == '1' ) {
    				$page_ads = $simple_ads_page_ads->get_count();
    				if ( $page_ads < $advertising_ads_per_page ) {
    					$content = $content . simple_ads_get_ad_code('after');
    					$simple_ads_page_ads->increase();
    				}
    			}
    		}
    	}
    	return $content;
    
    }
    
    remove_filter( 'the_content', 'simple_ads_output', 20 );
    
    add_filter('the_content', 'wpmudev_simple_ads_output', 20, 1);

    In the above snipped please replace the page/posts id's accordingly. This is the line which you should insert the ids:
    $no_ads_page_ids = array(1045, 1149, 1854, 3542);

    Hope this helps!

    Kind regards,
    Panos

  • Sajid

    Hi Frédéric,
    Hope you are doing good today :slight_smile:

    I hope you don't mind me chiming in here. Please try the below code to not show the ads on blog page (replace this with above provided code).

    function wpmudev_simple_ads_output( $content ){
    
    	$no_ads_page_ids = array(1045, 1149, 1854, 3542);//<=== Edit these ids :)
    
    	global $wpdb, $simple_ads_page_ads, $current_site, $post;
    
    	if ( is_home() ) return $content;
    
    	$advertising_ads_per_page = get_site_option('advertising_ads_per_page');
    	$advertising_main_blog = get_site_option('advertising_main_blog', 'hide');
    	$display_ads = 'yes';
    
    	if ( $wpdb->blogid == $current_site->id && $advertising_main_blog == 'hide' ) {
    		$display_ads = 'no';
    	}
    	if ( $display_ads == 'yes' ) {
    		if ( is_page() ) {
    			if ( get_site_option('advertising_location_before_page_content') == '1' ) {
    				$page_ads = $simple_ads_page_ads->get_count();
    				if ( $page_ads < $advertising_ads_per_page ) {
    					$content = simple_ads_get_ad_code('before') . $content;
    					$simple_ads_page_ads->increase();
    				}
    			}
    			if ( get_site_option('advertising_location_after_page_content') == '1' ) {
    				$page_ads = $simple_ads_page_ads->get_count();
    				if ( $page_ads < $advertising_ads_per_page ) {
    					$content = $content . simple_ads_get_ad_code('after');
    					$simple_ads_page_ads->increase();
    				}
    			}
    		} else {
    			if ( get_site_option('advertising_location_before_post_content') == '1' ) {
    				$page_ads = $simple_ads_page_ads->get_count();
    				if ( $page_ads < $advertising_ads_per_page ) {
    					$content = simple_ads_get_ad_code('before') . $content;
    					$simple_ads_page_ads->increase();
    				}
    			}
    			if ( get_site_option('advertising_location_after_post_content') == '1' ) {
    				$page_ads = $simple_ads_page_ads->get_count();
    				if ( $page_ads < $advertising_ads_per_page ) {
    					$content = $content . simple_ads_get_ad_code('after');
    					$simple_ads_page_ads->increase();
    				}
    			}
    		}
    	}
    	return $content;
    
    }
    
    remove_filter( 'the_content', 'simple_ads_output', 20 );
    add_filter('the_content', 'wpmudev_simple_ads_output', 20, 1);

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Best Regards,
    Sajid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.