Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I remove the_content and is_single advertisement from bbpress?

  • @mllapan

    Participant

    I have this function to display advertisement after first paragprah in posts:

    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() ) {
            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 );
    }

    The problem is that this function is somehow hooked to bbpress forum listing (forum description) to, and shows after forum description.
    So how can I remove it from bbpress so it affects only posts?

    See word “reklama1” after each forum description: https://mllapan.com/forumi/forum/magazin/

Viewing 3 replies - 1 through 3 (of 3 total)
  • @robin-w

    Moderator

    This is the bit which displays topics and replies in loop_single_reply

    <?php do_action( 'bbp_theme_before_reply_content' ); ?>
    
    <?php bbp_reply_content(); ?>
    
    <?php do_action( 'bbp_theme_after_reply_content' ); ?>

    you can hook to either of the action hooks here, or a filter in bbp_get_reply content which is called by bbp_reply_content which is in \includes\replies\template.php line 576 and ends with a filter

    return apply_filters( 'bbp_get_reply_content', $content, $reply_id );

    @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 );
    }

    @robin-w

    Moderator

    great – glad you are fixed 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar