WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How can I center my Adsense Ad? (9 posts)

  1. finox831
    Member
    Posted 2 years ago #

    Hi everyone, if you look at my website, wwww.eplreport.com the header ad at the very top is on the left and I would like to center it. How can i go about doing this and where do I have to add the css code at? I'm using mediapress theme.

    Thank you so much for taking the time to read this.

  2. Big Bagel
    Member
    Posted 2 years ago #

    The easiest way would probably be to wrap your ad code in a div:

    <div id="googleAd">...google ad code...</div>

    then add:

    #googleAd { text-align: center; }

    to the bottom of your theme's style sheet (style.css).

  3. Emphacy
    Member
    Posted 2 years ago #

    You can use a HTML center tag...

    <center><div id="adsense"> put code here </div><center>

    or include CSS code using the margin-left attribute to centre it.

    <div class="adsense"> put code here </div>

    <style>

    .adsense {
    margin-left: 50px
    }

  4. finox831
    Member
    Posted 2 years ago #

    this is the code i added in the header section, however it didn't work.

    <div class="adsense"> <script type="text/javascript"><!--
    google_ad_client = "pub-2542975605347305";
    /* 728x90, under banner 8/4/11 */
    google_ad_slot = "4287651566";
    google_ad_width = 728;
    google_ad_height = 90;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </div>
    <style>
    .adsense
    {
margin-left: 50px
    }

  5. Big Bagel
    Member
    Posted 2 years ago #

    The center tag is deprecated and really shouldn't be used anymore.

    margin-left will work as long as it's set to exactly half the remaining space (which in this case would be 116px) while text-align: center, since the div will automatically fill the entire width, will work regardless.

    In other words, surround your google ad code in a div with an id or class:

    <div id="adsenseAd">...code...</div>
    or
    <div class="adsenseAd">...code...</div>

    then use the id/class to center it using css:

    If you use an id:
    #adsenseAd { text-align: center; }
    or if you use a class:
    .adsenseAd { text-align: center; }

    You can also use margin-left instead:

    If you use an id:
    #adsenseAd { margin-left: 116px; }
    or if you use a class:
    .adsenseAd { margin-left: 116px; }

    but you will have to change that value if you ever change the overall width of your site/header/adsense ad.

  6. Big Bagel
    Member
    Posted 2 years ago #

    The css (.adsense { text-align: center; }) should be added to the bottom of your "style.css" file in your theme. You could also add:

    <style type="text/css">
        .adsense { text-align: center; }
    </style>

    right before the </head> tag in your theme's "header.php" file.

    Or, if you don't want to mess with any other files, use:

    <div style="text-align: center;">...your google ad code...</div>

  7. Big Bagel
    Member
    Posted 2 years ago #

    bah...

    For copy/paste purposes replacing all that ad code with:

    <div style="text-align: center;">
    <script type="text/javascript"><!--
    google_ad_client = "pub-2542975605347305";
    /* 728x90, under banner 8/4/11 */
    google_ad_slot = "4287651566";
    google_ad_width = 728;
    google_ad_height = 90;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </div>

    will center it.

  8. finox831
    Member
    Posted 2 years ago #

    it worked!!! thanks so much guys! I really appreciate it.

  9. journalismhub
    Member
    Posted 2 years ago #

    Dear all - I have a similar problem. I want to center the google ad at my site: http://journalismhub.com but I can't. I have followed all comments above - especially Big Bagel's comments yet they also did not work. Any suggestions please?

    For the record, I am not using amy google ad plugin (i use to not anymore). I am putting them in text in a sidebar widget.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.