Please disable your Ad Blocker to better interact with this website.

BLOG

See what we're whipping up!

/**
AdSense in Content
**/
function wpdev_add_adsense_content($content) {
  $ad1 = 'AD 1 CODE GOES HERE';
  $ad2 = 'AD 2 CODE GOES HERE';

  $content = explode('</p>', $content); // Break paragraphs into array
  $count = count($content); // Count paragraphs in array
  for($i = 0; $i < $count; $i++) {
    if($count > 3 && $i == 2) { // If more than 3 paragraphs, output ad at 2nd paragraph spot
      return $ad1;
    }
    if($count > 6 && $i == 5) { // If more than 6 paragraphs, output ad at 5th paragraph spot
      return $ad2;
    }
  }
  return $content[$i] . '</p>';
}
add_filter('the_content', 'wpdev_add_adsense_content');

No comments yet