any idea how to count paragraphs of a post so that I could insert ads etc after x paragraphs?
i know there are plugins already but i prefer to work without plugins
am looking to add something to functions.php, or else to single.php and page.php
any idea how to count paragraphs of a post so that I could insert ads etc after x paragraphs?
i know there are plugins already but i prefer to work without plugins
am looking to add something to functions.php, or else to single.php and page.php
<?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>";
} ?>
added this to single.php
source: http://wordpress.org/support/topic/show-first-and-second-paragraph-on-the-homepage
This topic has been closed to new replies.