0

I want to insert ads between comments.

function wpse_comments_ads_injection( $comment, $args, $depth ) {
    
 static $count = 0;

if ( $count == 2 ) {
        echo "AD 1"; 
    }

if ( $count == 5 ) {
        echo "AD 2"; 
    }

 $count++;
 }

add_filter( 'wp_list_comments_args', function( $args ) {
    if ( ! isset( $args['end-callback'] ) ) {
        $args['end-callback'] = 'wpse_comments_ads_injection';
    }
    return $args;
} );

I wrote this code, but because of it the tag

<!-- #comment-## -->
</li>

is deleted How will it be right?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.