WordPress.org

Ready to get started?Download WordPress

Forums

Google Ad between first and second post (2 posts)

  1. julianrin
    Member
    Posted 3 years ago #

    I'm trying to figure out a way to put a Google Ad between the first and second post on my blog. So far I haven't found a current way to do this with the Twentyten theme. Any help is appreciated.

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    i assume you have found loop.php ?

    and the actual loop code showing the front page ?

    and particularly the line <?php endwhile; // End the loop. Whew. ?> a few lines from the end ?

    before that line, add your adsense code, ideally wrapped into a div with a css class for formatting; and definitively surrounded with some extra code; for instance:

    <?php if( !$ad_shown ) { ?>
    <div class="adsense">
    <script type="text/javascript"><!--
    google_ad_client = "pub-0123456789098";
    /* adsense_ad */
    google_ad_slot = "123456789";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </div>
    <?php $ad_shown = true; } ?>

    be aware that this will now show adsense in most page with multiple posts - i.e. not only on the front page, but also in archives, search results, etc.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.