Add some constant message after the last paragraph
-
Hi,
Here’s some idea of mine to display a certain message after the last paragraph (i.e. notification or ads etc). I found lot of solutions showed as following:
<?php
$paragraphAfter= 1; //shows image after paragraph 1
$content = apply_filters(‘the_content’, get_the_content());
$content = explode(“</p>”, $content);
for ($i = 0; $i <count($content); $i++) {
if ($i == $paragraphAfter) { ?>
<div>INSERT HTML STUFF HERE</div>
<?php
}
echo $content[$i] . “</p>”;
} ?>The problem I’m having now is every post of mine will contain words and wordpress owned photos gallery. I would like display the HTML STUFF after last paragraph and before the gallery.
I knew it’s possible as I have tested the no. of $paragraphAfter, the HTML stuff will not display if the content’s paragraphs are lesser than the no. under $paragraphAfter. Means, the code above just count the <p> but not including (before) the gallery (<div class=”gallery-1″> automatically generated by wordpress script – media.php)
I believe the solution, should be calculating what’s the no. of last paragraph and appear as the no. for $paragraphAfter. Anyone assist? Thanks.
- The topic ‘Add some constant message after the last paragraph’ is closed to new replies.