If you load the content into a string using the get_the_content function, you’ll be able to insert the AdSense code any where you’d like by determining where you want it and simply pasting the code.
For example:
$code = '
<script type="text/javascript"><!--
google_ad_client = "pub-9144171931162286";
/* 300x250, created 8/10/08 */
google_ad_slot = "0878512762";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
';
$text = get_the_content();
$text = substr_replace($text, "<p>", $code."<p>");
echo $text;
This example will insert your AdSense code ($code) into the content of your post ($text) at the beginning of each paragraph by replacing the <p> with $code<p>.
Depending upon where you’d like the code to actually appear, you’ll have to modify the substr_replace command. One way to easily accomplish what you’d like is to include a special tag in the post where you want the ad to appear and then replace it with the substr_replace command.