Wordpress - Adsense after post hack
An easy hack this one. A simple way to ad Google ads (or any other content) into a predefined number of posts from the start of the loop. The exact code changes will vary depending on your exact template, but these instructions should work for most.
Edit your index.php and find the loop (highlighted below).
Then simply add in the code between <<add this code start>> and <<add this code end>>and your selected Google ad code in the equivalent of the place marked below.
<?php while (have_posts()) : the_post(); ?> <<this is the start of the loop>>
<div class=”post” id=”post-<?php the_ID(); ?>”><h1><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
<?php the_title(); ?></a></h1>
<p class=”meta”><?php the_time(’F jS, Y’) ?> by <?php the_author() ?></p>
<div class=”entry”>
<?php the_content(’Read the rest of this entry »’); ?>
</div><<add this code start>>
<?php $lb_firstfew=$lb_firstfew+1;?>
<?php if ($lb_firstfew==1) { ?><div>
<<your Google code goes here>>
</div><?php } ?>
<<add this code end>><p class=”info”>Posted in <?php the_category(’, ‘) ?> <strong>|</strong>
<?php edit_post_link(’Edit’,”,’<strong>|</strong>’); ?>
<?php comments_popup_link(’No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?></p>
</div>
<?php comments_template(); ?>
<?php endwhile; ?> <<this is the end of the loop>>
This example simply adds in the Google code after the first post.
You can obviously amend the condition <?php if ($lb_firstfew==1) { ?> to place ads in your selected number of posts.
Don’t forget the Adsense TOS - AdSense publishers may place up to three ad units on one web page.
Posted in Wordpress | No Comments »
