Skip to content

Instantly share code, notes, and snippets.

@ryanriatno
Created December 29, 2012 05:53
Show Gist options
  • Save ryanriatno/4404803 to your computer and use it in GitHub Desktop.
Save ryanriatno/4404803 to your computer and use it in GitHub Desktop.
Insert Ads inside Post Content
<?php
add_filter('the_content', 'rr_add_ad_inside_post');
function rr_add_ad_inside_post($content) {
if ( is_single() ) {
$paragraphAfter= 3; //display after the first paragraph
$content = explode("", $content);
for ($i = 0; $i <count ($content); $i++ ) {
if ($i == $paragraphAfter) { ?>
<p class="alignleft">
<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxx";
/* 250x250, created 9/10/11 */
google_ad_slot = "xxxxxxxxx";
google_ad_width = 250;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</p>
<?php }
echo $content[$i] . "</p>";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment