How do I show google ads between post content?

You can use a shortcode or the_content filter. I think the_content filter is better because your don’t introduce any string in your post, so the content can be exported and used in another platforms if needed. For emxample, for show a block of adsense after the first parragraph:

 add_filter( 'the_content', 'tbn_ads_inside_content' );
 function tbn_ads_inside_content( $content ) {
     
      $output = $content;
      //We don't want to modify the_content in de admin area
      if( !is_admin() ) {
          $ads = "<p>your_ads_code</p>";
          $p_array = explode('</p>', $content );
          $p_count = 1;

          if( !empty( $p_array ) ){

              array_splice( $p_array, $p_count, 0, $ads );
              $output="";

              foreach( $p_array as $key=>$value ){

                  $output .= $value;

               }
          }

      }

      return $output;

 }

Leave a Comment