I am trying to output an image in between every XX post shown on the /category/archive pages for every category. Years ago there was a tutorial online of how to do this, but I can't seem to find it now.

I am writing a plugin that allows the admin to upload an image with a link to the image to create an advertisement on the site and have it show between every 10 posts shown on the category page. What hook would I use for this and would I need to loop through the posts before they are shown?

Any help would be greatly appreciated.


If you can update your theme files, just update category.php and archive.php this way:

    $counter = 0; 
    while ($the_query->have_posts()) : 

<?php if ($counter % 4 == 0) : ?>
    <div class="my-ad">my ad</div>
<?php endif; ?>

    <div class="post">
        <?php the_title(); ?>



You can also change archive/category template by your own via plugin with template_include hook.

If you can't access your theme, use loop_start or loop_end hooks:

add_action( 'loop_start', function( $query ){
     if( $query->is_category() ){


Then place your ads between posts with js.

You can also hook to the_post or the_content, check if it on category/archive template and add your ads according global count variable

  • on the surface this looks like a great solution. i'll update you when this task is finished on my end and if i have any questions during that process. – Zach Smith Aug 23 '17 at 11:30

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