EN / ZH
WordPress Tips: Inserting Ads After Any Post on the Homepage

It’s been a while since I’ve updated the blog, so here’s a quick WordPress tip — nothing too technical. This article covers how to display custom ads after any post on your WordPress site’s homepage.

In your index.php file, find <? php the_content(); ?> and add the following code right after it (the code must be placed inside the main loop):

<?php if ($wp_query->current_post == 0) : ?>

<!--Your ad code here--!>

<?php endif; ?>

The 0 in current_post == 0 represents the position: which post to insert the ad after (counting starts from 0). For example, to insert an ad after the fourth post, change 0 to 3.

Simple as that — effortlessly insert ads after any post on your WordPress homepage.