I am using this code to insert ad code after first para in every post.
//Insert AD after second para of the post
add_filter( 'the_content', 'post_ads' );
function post_ads( $content ) { $ad_code = '<div>
AD CODE HERE
</div>';
if ( is_single() && ! is_admin() )
{ return ad_after_para( $ad_code, 1, $content ); }
return $content; } // Function that makes this Work
function ad_after_para( $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 ); }
Now I added woocommerce in the site. Same ad is appearing on product pages too.
I need this ad only on blog posts.
Please suggest the modification in this snippets to achieve this.
Thank You