info To participate please Register or Login.

Advertisements after first post in WordPress

By Simon on January 23rd, 2008. Published in Blogging.

Here is a simple way to put an AdSense ad, or any other ad for that matter, after the first post in your WordPress blog. This will only work on your main page, not on an individual post page.

Okay, let’s get started. Open up your index.php file or go into the WordPress control panel > Presentation > Theme Editor and choose Main Index Template on the right

Find the line that starts with:

<?php if (have_posts())

Add this line of code above it:

<?php $count = 1; ?>

Find the line that starts with:

<?php the_content

Add this code below its closing tag:

<?php if ($count == 1) : ?>
Your Google AdSense code
<?php endif; $count++; ?>

Upload and update everything and see so everything works. You can easily customize this spot using CSS. You can also publish the advertisement after the second post or the third etc. Just change:

“count == 1? to “count == 2?

One Response

Express yourself. Tell us your opinion. Make a comment!

  • Nice post. Just to add, if you wanted to have the advert after both the first AND the second post change count==2 to count<=2

    Jim

  • Write your comment

    Warning Spam and inflammatory comments will be deleted. If this is the first time you make a comment on Easy Webbers it will be held for moderation before being published.