Insert Adsense Code Between WordPress Posts

Best place for adsense codes is between the post where it can click more. Mostly wordpress blogers use plugins for this but you can place the below code in your functions.php theme file before end of PHP “?>” tag.

function ad_content($content) {
    $postParas = explode("</p>", $content);
    $content = '';
    for ($i = 0; $i < count($postParas); $i++) {
        if ($i == '1') { //place ads after first paragraph
            $content .= 'YOUR_ADD_CODE';
        }
        $content .= $postParas[$i] . "</p>";
    }
    return $content;
}
 
add_filter('the_content', 'ad_content');

Leave a Reply

Your email address will not be published. Required fields are marked *