Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: How do I remove the_content and is_single advertisement from bbpress?

@mllapan

Participant

Thanks, but I found this is_bbpress function, and solved it.

add_filter( 'the_content', 'post_ads_1_paragraph' );
 
function post_ads_1_paragraph( $content ) {
    $ad_code = '<div class="advert" style="display: none;">Reklama1</div>';
 
    if ( is_single() && ! is_admin() && ! is_bbpress() ) {
        return prefix_insert_after_1nd_paragraph( $ad_code, 1, $content );
    }
	
    return $content;
}
  
function prefix_insert_after_1nd_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 );
}
Skip to toolbar