Have you ever wondered how to show Google ads on your WordPress blog’s home page, but only after the very first article? Well, here is how you do it. And don’t worry, it’s quite simple, and you can’t permanently damage anything by giving it a try. ANYONE can do this!
- In the PRESENTATION menu, under THEMES EDITOR, find the theme file called “Main Index Template” (index.php).
- FIRST: Copy and paste everything you see here into a blank text file and save it. This way if you screw something up you can revert back to the original without hurting anything.
- Find a line of code that looks much like the following:
<?php the_content('Read the rest of this entry »'); ?>
- Immediately after that, paste the following:
<?php if ($count == 0) : ?> ENTER YOUR AD CODE HERE <?php endif; $count++; ?>
- Save the document and refresh your page. You should see the ad ONLY after the first article on the homepage.
So as an example, here is what the code might look like when installed (the red part is the new part):
<h1 class=”title”><?php the_title(); ?></h1>
<p class=”PostInfo”>Posted on <?php the_time(‘M d, Y – g:ia’); ?> <?php comment_time() ?> by <?php the_author() ?> in <?php the_category(‘, ‘) ?></p>
<?php the_content(‘Read the rest of this entry »’); ?>
<?php if ($count == 0) : ?>
<div class=”frontpage-google-ad” style=”border: dashed 1px black; padding: 10px” align=”center”>
google_ad_client = “pub-0617773482327857”;
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = “468x60_as”;
google_ad_type = “text_image”;
<?php endif; $count++; ?>
If it doesn’t show up in the right place, just try moving it around a bit and use a little trial and error. Also, remember to disable WP-Cache while you are testing the changes. If your pages are cached you won’t see the changes and it might throw you off a bit. You can enable it after you are satisfied.