Title: Show multiple ads Between post using function codes
Last modified: November 18, 2021

---

# Show multiple ads Between post using function codes

 *  [মোঃ আশিকুর রহমান](https://wordpress.org/support/users/tvhex/)
 * (@tvhex)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/show-multiple-ads-between-post-using-function-codes/)
 * For multiple ads on post
    I have implemented first code and it perfectly work.
   But iam not good at coding so can you tell me how to show multiple ads? This 
   second code how to implement it properly can you help me with it? Also for multiple
   ads do i need to create second in article ads code? Or i can use the same ads
   code twice?
 *     ```
       //Insert ads after third paragraph of post content.
   
       add_filter( 'the_content', 'insert_post_ads' );
   
       function insert_post_ads( $content ) {
   
           $ad_code = '<div>Insert your Ads code here</div>';
   
           if ( is_single() && ! is_admin() ) {
               return prefix_insert_after_paragraph( $ad_code, 3, $content );
           }
   
           return $content;
       }
   
       // Parent Function
   
       function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) 
       {
           $closing_p = '</p>';
           $paragraphs = explode( $closing_p, $content );
           foreach ($paragraphs as $index => $paragraph) {
   
               if ( trim( $paragraph ) ) {
                   $paragraphs[$index] .= $closing_p;
               }
   
               if ( $paragraph_id == $index + 1 ) {
                   $paragraphs[$index] .= $insertion;
               }
           }
   
           return implode( '', $paragraphs );
       }
       ```
   
 * And this code:
 *     ```
       2
       3
       4
       5
       6
       7
       8
       9
       10
       11
       $first_ad_code = ‘Ads code goes here’;
   
       $second_ad_code = $first_ad_code;
   
       if ( is_single() && ! is_admin() ) {
       $content = prefix_insert_after_paragraph( $first_ad_code, 3, $content );
       $content = prefix_insert_after_paragraph( $second_ad_code, 6, $content );
       return $content;
       }
       return $content;
       }
       ```
   
 * I can’t merge this codes. Please help.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fshow-multiple-ads-between-post-using-function-codes%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

The topic ‘Show multiple ads Between post using function codes’ is closed to new
replies.

 * 0 replies
 * 1 participant
 * Last reply from: [মোঃ আশিকুর রহমান](https://wordpress.org/support/users/tvhex/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/show-multiple-ads-between-post-using-function-codes/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
