Support » Fixing WordPress » How to use ads after every 3 pragrapah

  • Resolved Urmil Patel

    (@urmilwp)


    we are checking paragraph with </p> tag but empty <p> tag also counting so every 3 paragraph logic is not working due to empty <p> tag

    we are checking paragraph like this

    $closing_tag = '</p>';
    $paragraphs = explode( $closing_tag, $content );
    foreach ( $paragraphs as $index => $paragraph ) {
           //here we want to check whether $paragraph is empty or not something like
           if($paragraph === '<p>&nbsp;'){
              echo "empty";
           }
    
    }
    • This topic was modified 9 months, 3 weeks ago by Urmil Patel.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Why are there empty p tags? There should not be. That is not correct html.

    Use this in your functions.php or code snippet:

    add_filter(‘the_content’, ‘insert_ad_block’);

    function insert_ad_block( $text ) {

    if ( is_singular( array( ‘post’, ‘page’) )) {

    $ads_text = ‘put your ad code here’;

    return prefix_insert_after_paragraph( $ads_text, 3, $text );}
    return $text;

    }

    Repeat but put a 6, 9, 12 instead of a 3.

    • This reply was modified 9 months, 3 weeks ago by stevenhermans.

    Thank you so much….

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to use ads after every 3 pragrapah’ is closed to new replies.