Support » How-To and Troubleshooting » [Resolved] How can I center my Adsense Ad?

[Resolved] How can I center my Adsense Ad?

  • 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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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).

    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>


    .adsense {
    margin-left: 50px

    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”;
    /* 728×90, under banner 8/4/11 */
    google_ad_slot = “4287651566”;
    google_ad_width = 728;
    google_ad_height = 90;
    <script type=”text/javascript”
    src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”> </div>
margin-left: 50px

    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>
    <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.

    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; }

    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>


    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 type="text/javascript"

    will center it.

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

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] How can I center my Adsense Ad?’ is closed to new replies.