Title: Will This Code Work?
Last modified: June 11, 2021

---

# Will This Code Work?

 *  [Anirban Roy](https://wordpress.org/support/users/heyanirban/)
 * (@heyanirban)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/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 [iSaumya](https://wordpress.org/support/users/isaumya/)
 * (@isaumya)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/will-this-code-work/#post-14546989)
 * 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)

The topic ‘Will This Code Work?’ is closed to new replies.

 * ![](https://ps.w.org/ad-invalid-click-protector/assets/icon-256x256.png?rev=1534940)
 * [Ad Invalid Click Protector (AICP)](https://wordpress.org/plugins/ad-invalid-click-protector/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ad-invalid-click-protector/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ad-invalid-click-protector/)
 * [Active Topics](https://wordpress.org/support/plugin/ad-invalid-click-protector/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ad-invalid-click-protector/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ad-invalid-click-protector/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [iSaumya](https://wordpress.org/support/users/isaumya/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/will-this-code-work/#post-14546989)
 * Status: not resolved