Adding AdSense to WordPress category and archive results

This tutorial explains how to add Google AdSense ads to your WordPress category and archive listing result pages. While plugins exist for this purpose, manually adding ads gives you full control over placement and appearance. The process is simple and should only take a few minutes to implement.

How to Add Google AdSense Ads to Category and Archive Result Pages

  1. Log into your WordPress admin panel.
  2. From the menu, select Presentation → Theme Editor.
  3. In the Theme Editor, select the archive.php file from the list on the right.
  4. Find the following line:

    <?php if (have_posts()) : ?>

  5. Directly above that line, add this code:

    <?php $count = 1; ?>

  6. Next, find the line:

    <div class="entry">

  7. Immediately below it, add the following code, replacing AdSense Code with your actual AdSense ad code:

    <?php if ($count == 1) : ?>

    AdSense Code

    <?php endif; $count++; ?>

  8. Click Update File to save your changes.
  9. Visit your site’s category or archive pages to confirm the ads appear where expected.

Note: To change which post the ad appears under, modify the number in the condition. For example, $count == 3 will display the ad under the third post on the results page.