The function below is used to show certain content after the first paragraph. I would like to show ‘content X’ after the 1st paragraph and ‘content Y’ after 2nd paragraph.
<?php
$paragraphAfter= 1; //display after the first paragraph
$content = apply_filters('the_content', get_the_content());
$content = explode("</p>", $content);
for ($i = 0; $i <count($content); $i++ ) {
if ($i == $paragraphAfter) { ?>
<div>Insert content here</div>
<?php }
echo $content[$i] . "</p>";
} ?>
I appreciate any help.
My way to do this (see update below):
Answer is updated according to subsequent comments:
I knew it’s old question but this answer should help the people still looking for it.
This plugin works perfectly in any theme.
https://wordpress.org/plugins/insert-post-ads
You can choose first / second or whatever you like to display your ads.
I was looking for a way to make calls get_template and here I share it in case it is useful