I use a code like the one shown below to insert ads after the first paragraph.
The problem is that this code requires the content to be displayed within paragraph tags and I would like to use this code to insert a DIV.
When I simply replace the tags with div tags the code no longer works.
How do I remove the paragraph tags from the code while allowing the code to remain functional?
<?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) { ?>
CONTENT GOES HERE
<?php }
echo $content[$i] . "</p>";
} ?>
I need to stress that I think this is going to be very unstable and you may not always get the results you want, but in simple cases this should work.
This one is similar to the one posted above, however there is an extra loop to display all paragraphs after the content.
wpautop( get_the_content() )
passes formatted post content to be split through paragraph tags withexplode('</p>', $content)
andforeach
to loop all paragraphs after the fold.