title: Want to add additional function (of determining number of paragraphs in an article) to ad inserting plugin
body: <p>I'm using a site specific plugin to insert ads between paragraphs of my blog post. The plugin works smooth. It's code is like this-</p>
  
  <pre><code>&lt;?php
  //Insert ads after second paragraph of single post content.
  add_filter( 'the_content', 'prefix_insert_post_ads' );
  function prefix_insert_post_ads( $content ) {
  $ad_code = '&lt;div&gt;Ads code goes here&lt;/div&gt;';
  if ( is_single() &amp;&amp; ! is_admin() ) {
  return prefix_insert_after_paragraph( $ad_code, 2, $content );
  }
  return $content;
  }
  // Parent Function that makes the magic happen
  function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content) 
  {    
  $closing_p = '&lt;/p&gt;';
  $paragraphs = explode( $closing_p, $content );
  foreach ($paragraphs as $index =&gt; $paragraph) {
  if ( trim( $paragraph ) ) {
  $paragraphs[$index] .= $closing_p;
  }
  if ( $paragraph_id == $index + 1 ) {
  $paragraphs[$index] .= $insertion;
  }
  }
  return implode( '', $paragraphs );
  }`
  </code></pre>
  
  <p>It works well and displays ad code wherever it is asked to. </p>
  
  <p>I want to add another function into it. I want the plugin to determine the number of paragraphs available in a post and display ad only if the post has a minimum number of paragraphs (say 10).</p>
  
  <p>In short, the plugin must display ad only if there are at least 10 paragraphs in the article. If a post is shorter than that, the ad shouldn't be shown by the plugin.</p>
  
  <p>Can anyone help me out with this task?</p>
  
  <p>Any help would be highly appreciated.</p>