Support » Plugin: Ad Invalid Click Protector (AICP) » Will This Code Work?

  • Hi Saumya da!

    My name is Anirban. I recently noticed some unnatural activity in my adsense account and after some research, came accross your plugin. It’s a fantastic plugin and I am extremely grateful to you for building this plugin.

    I am not using any 3rd party plugin to display ads on my site. I use my own code to display the ads. I have edited my code to integrate your plugin with it. Could you please take a look at the snippet given below and let me know if you find any conflicts?

    function techrbun_insert_ads_after_words($content)
    { 
       if (aicp_can_see_ads() && is_single()) {
    	$techrbun_ad_code = '
    	<br/>
    	<div class="aicp">
    	<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    	<!-- Article Top -->
    	<ins class="adsbygoogle"
    		 style="display:block"
    		 data-ad-client="ca-pub-4795578973356153"
    		 data-ad-slot="1888103060"
    		 data-ad-format="auto"
    		 data-full-width-responsive="true"></ins>
    	<script>
    		 (adsbygoogle = window.adsbygoogle || []).push({});
    	</script>
    	</div>
    	<br/><br/>';
    	if (function_exists('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint()) {
    		$techrbun_ad_code = '
    		<br/>
    		<amp-ad width="100vw" height="320"
    		type="adsense"
    		data-ad-client="ca-pub-4795578973356153"
    		data-ad-slot="1888103060"
    		data-auto-format="rspv"
    		data-full-width="">
    	 <div overflow=""></div>
       </amp-ad>
       <br/>';
    	}
    	$techrbun_final_article = "";
    	$techrbun_should_insert = false;
    	$techrbun_after_chars = 1500;
    	$techrbun_content_length = strlen($content);
    	$techrbun_para_tag = "";
    	$techrbun_curr_len = 0;
    	if ($techrbun_content_length > $techrbun_after_chars) {
    		for ($i = 0; $i < $techrbun_content_length; $i++) {
    			if ( !$techrbun_should_insert)
    				$techrbun_curr_len++;
    			$techrbun_final_article = $techrbun_final_article . substr($content, $i, 1);
    			$techrbun_para_tag = $techrbun_para_tag . substr($content, $i, 1);
    			if ($techrbun_curr_len == $techrbun_after_chars) {
    				$techrbun_should_insert = true;
    				$techrbun_curr_len = 0;
    			}
    			if ($techrbun_para_tag == '</p>' && $techrbun_should_insert) {
    				$techrbun_final_article = $techrbun_final_article . $techrbun_ad_code;
    				$techrbun_should_insert = false;
    			}
    
    			if (strlen($techrbun_para_tag) == 4)
    				$techrbun_para_tag = "";
    		}
    		return $techrbun_final_article;
    	} else return $content;
    	} else
    		return $content;
    }
    
    add_filter('the_content', 'techrbun_insert_ads_after_words');

    Thank you!

Viewing 1 replies (of 1 total)
  • Plugin Author Saumya Majumder

    (@isaumya)

    AICP won’t work for the AMP pages. It will only work on the normal pages.
    So, in you code you should have a block for the aicp, another for AMP ads and so on…

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.