Injecting ads in all my posts

So my have recently got approved by Adsense and Media.net. Now what I want to do is that inject ad in between the post. How can I do that in a single go? I don’t want to edit every single post and inject the ad.

Use AdInserter wordpress plugin

OR

Similar plugins

I have been using this code in functions.php to insert add after 4th paragraph.

 
add_filter( 'the_content', 'prefix_insert_post_ads' );
 
function prefix_insert_post_ads( $content ) {
     
    $ad_code = '<div>
Your AdSense Code
</div>';
 
    if ( is_single() && ! is_admin() ) {
        return prefix_insert_after_paragraph( $ad_code, 4, $content );
    }
     
    return $content;
}
4 Likes

Change the number, if you want to insert between the paragraph.
Thanks. Hope it works

1 Like