• Hi,

    I’ve managed after reading the forumt o place adsense on my wordpress blog. It looks ok….

    except….every time I post, it posts new adsense ads as well.

    What I did:
    I placed the adsense code in the wp-content/themes/default/index.php file,
    (after….”” <small><?php the_time(‘F jS, Y’) ?> <!– by <?php the_author() ?> –></small> “,

    ………….. and before………..

    “” <div class=”entry”>
    <?php the_content(‘Read the rest of this entry »’); ?> “”)

    So it’s now in the header of my blog. Problem is with every post, it posts a new adsense block of ads. How do I change this so that it only appears once per header?

    xdhirax

Viewing 8 replies - 1 through 8 (of 8 total)
  • Put it after <div id="content" class="narrowcolumn">

    That’s not the header of the blog, that’s the header of the post. If you want it in the header of the blog, you need to look for something like:

    <h1 id="header"><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a>
    </h1>

    <div id="content">

    and put your code before <div id="content>

    Be aware that depending on your theme and stylesheet, that may really look awful. To do a really good job of putting it in the header, you need to make the header id a <div id="header"> change the < h1 id="header"> to a plain old <h1> and put both the Headline and the adsense code inside the header div. You may have to tweak your stylesheet some to accomplish that, too.

    You’re going to get best clickthrough by having the ad in the post, though.

    Thread Starter xdhirax

    (@xdhirax)

    Thanks guys, I tried both suggestions and s_g, your placement works perfectly.

    tomhanna, the “look awful” bit (ads ‘sliding’ off the page) happens if the code is placed BEFORE <div id=”content> It should, as s_g says, be placed after and it will be fully on the page.

    One more queston for you….you said “You’re going to get best clickthrough by having the ad in the post, though.”

    Is there a way to automatically insert adsense into the middle (or end) of a post (without using a plugin)?

    Thanks again
    xdhirax

    Yeah, it works in some themes and looks horrible in others, but if you actually want it in the header section, it has to be before the content div (by definition).

    To get adsense in the post without a plugin, you can put it in the upper right corner with something like this:

    <div style="float:right; margin:2px;">

    ---your adsense code here ---

    </div>

    You can include that in your Main Template in the post section, but be aware that you are only supposed to have 3 ad units per page. My experience is that Google automatically limits you to 3 ad units, but their TOS still mentions it that you are only supposed to place 3 units per page. You can always set the WordPress reading options to show at most 3 posts if you’re concerned by that.

    You can also place one of the smaller banner styles (234×60 or 468×60 depending how wide your posts are) at the bottom of the post by just putting the code right after ‘<?php the_content(__(‘(more…)’)); ?>’ . The same caveat about ad units per page applies.

    Thread Starter xdhirax

    (@xdhirax)

    Thanks again tomhana,

    I tried your suggestion and I also tried the one I found on this post here: https://www.ads-software.com/support/topic/12685

    It seemed more like what I was looking for and was a little easier to do, (however in it you need ot look at hte last post and insert the code they suggest except the actual codes with the newe wordpress, the places to place the codes are”
    before ” <?php while (have_posts()) : the_post(); ?>
    and
    before ” <?php endwhile; ?> “

    Now I’ve got everythingI want without violating googles TOS, I wondered for my last question how to ad one more adsense block at the BOTTOM

    Thread Starter xdhirax

    (@xdhirax)

    Thanks again tomhana,

    I tried your suggestion and I also tried the one I found on this post here: https://www.ads-software.com/support/topic/12685

    It seemed more like what I was looking for and was a little easier to do, however in it you need to look at the last post and insert the codes they suggest (except the actual codes with the newer wordpress, the places to place the codes are)
    before ” <?php while (have_posts()) : the_post(); ?>”
    and
    before ” <?php endwhile; ?> “

    Now I’ve got everythingI want without violating googles TOS, I wondered for my last question how to add one more adsense block at the BOTTOM of the WordPress index page……

    I’m going to guess I need to add the code to ” <?php get_footer(); ?> ” – am I right? If so, would it be before or after that?

    xdhirax

    Thread Starter xdhirax

    (@xdhirax)

    Sorry ’bout the double post above.

    Here’s an example of adsense on top and bottom of the page…..

    https://awebbiz.com/blog/

    Where do I add it to show up on the bottom without sliding off the page?

    xdhirax

    Looks like, in the example you gave, he added it before <?php get_footer();> so if your theme is similar you should get similar results.

    I’m basing that off the structure of the themes I have used, where the sidebar is actually called in the footer.php file. His script code is right in front of the </div> that is the second thing in the footer files in those themes after <!-- begin footer -->. You could edit footer.php and put the code between <!-- begin footer --> and </div> and you should get the same result that way also.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How To make adsense only post in the header?’ is closed to new replies.