If you want a specific place to add your codes, you could build a shortcode and then you could place something like [place-add]
in your content in the exact place where you want the ad to appear.
If you don’t want to add a shortcode to your text, you can build a filter on the_content
. In that case you need to define a general place to instert the codes, for instance right before the second paragraph. That would work like this:
add_filter ('the_content','wpse265825_add_ad');
function wpse265825_add_ad($content) {
$ad = 'this is my ad code';
// find the second paragraph
$pos = strpos($content, '<p>', strpos($content, '<p>') + 1);
// insert code in that position
$content = substr_replace($content, $ad, $pos, 0);
return $content;
}
(I didn’t test the code, so some debugging may be necessary)