I currently trying to insert a block of custom code inside the WordPress posts loop which is using JetPack's infinite scroll functionality. In theory, this should be quite simple but is proving otherwise.

this is what I have currently written:

        $count = 0;
        while( have_posts() ) :

            get_template_part( 'content-post', get_post_format() );
            if ($count === 4) {
                get_template_part( 'block-one', get_post_format() );

            $count ++;

So, if the count is at 4 insert the custom block. However, when I look at my homepage, I get this view:

enter image description here

The custom code block has been added before the posts. I can't quite find out why.

Any suggestions?


Here is the content.php:

<a class="post-container-home" href="<?php the_permalink() ?>">
        style="background: url(<?php the_post_thumbnail_url() ?>)"
    <div class="post-info-home">
        <div class="post-time">
            <h3>min read</h3>

Here is block-one.php:

<div id="newsletter" class="post-container-home">
    <img src="/theme-new/wp-content/themes/theme-blog-new/img/subscribe.png" alt="subscribe">


  • Hard to tell without seeing the individual template parts, but it's likely that the block-one part is echoing or directly outputing, while the content-post is returning. – WebElaine May 12 at 17:28
  • @WebElaine Added those two templates to the post. – Charlie Coplestone May 12 at 18:21

I'm a fool.

I just noticed I'm trying to use content-post when I changed it to just content.

All working now.


| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.