WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] AdSense To Header (24 posts)

  1. Stergos
    Member
    Posted 2 years ago #

    Hi, i use twenty eleven theme actually a child theme. I try to add AdSense to Header (header.php) to the top right corner but i am not sure where i should place the AdSense code to do that, any help appreciated thank you!

  2. Ryan Yu
    Member
    Posted 2 years ago #

    Where are you trying the add the adsense, on the header or beside header?

    Either way you will have to alter your header.php file to add the adsense code.

  3. Stergos
    Member
    Posted 2 years ago #

    Hi and thanks for reply, i try to add a banner at the top right of the header, like this site: http://statcounter.com/.

    I know that i have to place the code to header.php but i am not sure where exactly and if i need to place any alternative codes with adSence like <right></right>...

    Thanks for advance!

  4. Ryan Yu
    Member
    Posted 2 years ago #

    There's no adsense on the site you mentioned,
    but I guess you want to add the adsense like the yellow box from the screenshot (the ad size is 468 x 60).
    http://postimage.org/image/tqiri7m95/

    To do this, open header.php and on line 102, find the code below:

    <?php
    	// Has the text been hidden?
    	if ( 'blank' == get_header_textcolor() ) :
    ?>
    	<div class="only-search<?php if ( ! empty( $header_image ) ) : ?> with-image<?php endif; ?>">
    	<?php get_search_form(); ?>
    	</div>
    <?php
    	else :
    ?>
    	<?php get_search_form(); ?>
    <?php endif; ?>

    Comment out the search function and add top-adsense div box.
    So it will look something like:

    <div id="top-adsense">
        <!-- adsense code goes here -->
    </div>
    <?php
    	// Has the text been hidden?
    	if ( 'blank' == get_header_textcolor() ) :
    ?>
    	<div class="only-search<?php if ( ! empty( $header_image ) ) : ?> with-image<?php endif; ?>">
    	<?php //get_search_form(); ?>
    	</div>
    <?php
    	else :
    ?>
    	<?php //get_search_form(); ?>
    <?php endif; ?>

    Open style.css and add the css code:

    #top-adsense {
    	width:468px;
    	height:60px;
    	position:absolute;
    	right:3.6%;
    	top: 3.5em;
    }

    Let me know if it works ok :)

  5. Stergos
    Member
    Posted 2 years ago #

    Not really it was place the banner above of menu and below of header image, any other ideas?

    http://statcounter.com/
    (when i open this site i see a banner to the top-right corner on the header image)

  6. Ryan Yu
    Member
    Posted 2 years ago #

    Sorry I cannot see any adsense from the site.
    Can you take a screenshot and show me?

  7. Stergos
    Member
    Posted 2 years ago #

    Oh i'm so sorry this is available only to users... Here how is like!
    statcounter

  8. Ryan Yu
    Member
    Posted 2 years ago #

    I see. To add the banner below the header graphic and above the menu,
    add this code uder the search form area.

    Same as above, find this code from header.php;

    <?php
    	// Has the text been hidden?
    	if ( 'blank' == get_header_textcolor() ) :
    ?>
    	<div class="only-search<?php if ( ! empty( $header_image ) ) : ?> with-image<?php endif; ?>">
    	<?php get_search_form(); ?>
    	</div>
    <?php
    	else :
    ?>
    	<?php get_search_form(); ?>
    <?php endif; ?>

    and add the "top-adsense" div below the code above.
    So it will look something like;

    <?php
    	// Has the text been hidden?
    	if ( 'blank' == get_header_textcolor() ) :
    ?>
    	<div class="only-search<?php if ( ! empty( $header_image ) ) : ?> with-image<?php endif; ?>">
    	<?php get_search_form(); ?>
    	</div>
    <?php
    	else :
    ?>
    	<?php get_search_form(); ?>
    <?php endif; ?>
    <div id="top-adsense">
    	<!-- Your Adsense goes here -->
    </div>

    and add the css code to style.css;

    #top-adsense {
    	width:468px;
    	height:60px;
    	background:yellow;
    	margin:10px auto;
    }

    Let me know how it went.

  9. Stergos
    Member
    Posted 2 years ago #

    geeksfolder thanks for you reply, i did not try it yet cause i have problems moving my site to another server but i will try it soon, thanks again!!!

    p.s. i just try it for a second but is the same think.

    I use NomNom child theme and it's not have the above code to the header.php but i try to find the place it should be. Okay this is my header code:

    [large amount of code removed - please follow the forum guidelines for posting code]

  10. Stergos
    Member
    Posted 2 years ago #

    Anyone please???

  11. Ryan Yu
    Member
    Posted 2 years ago #

    If you are using NomNom theme,
    add the div box right above the code below in header.php (line 128);

    <?php
    	// Has the text been hidden?
    	if ( 'blank' == get_header_textcolor() ) :
    ?>

    and also add the css code from my previous comment to style.css

  12. Stergos
    Member
    Posted 2 years ago #

    geeksfolder the complete code above is from the Header.php and as you can see the code you telling me "if ( 'blank' == get_header_textcolor() ) :" is not exist...

  13. Ryan Yu
    Member
    Posted 2 years ago #

    You should see the code in the original NomNom theme.
    But ye it seems you have altered the header.php...

    Within your code, add the div box right below;

    <?php endif; // end check for removed header image ?>

    Not 100% sure if it would work though as the code you have is different to what I have downloaded from NomNom site.

    Let me know if it works ok.

  14. Stergos
    Member
    Posted 2 years ago #

    Already try to add div below there, by doing this is create a space with the ad on it between the header image and menu. Is looking really bad ^^

  15. Stergos
    Member
    Posted 2 years ago #

    It's must be some way to do this.... not only for advertising but for customizing too now is so empty!!!

  16. zeaks
    Member
    Posted 2 years ago #

    What Geeksfolder posted works, but the adsense should be placed inside the <div id="nomnom-header">, then use top: 0; and right: 0;

  17. Stergos
    Member
    Posted 2 years ago #

    Zeaks you are my man dude ;)

  18. Stergos
    Member
    Posted 2 years ago #

    I search enough posts to find the solution but without success, if any of you has the same problem the solution is zeaks.org

  19. Janell2
    Member
    Posted 2 years ago #

    Hi Geeksfolder,
    Your code to place the banner ad on top of the branding/header worked perfectly. It took forever to find a correct answer to this. Congrats and many thanks.
    Janell

  20. Ryan Yu
    Member
    Posted 2 years ago #

    Awesome Janell2! :)

  21. niceWP
    Member
    Posted 2 years ago #

    May i ask you guys, how to place the 728x90 AdSense on the right side on the header (instead of the search-box), and 260x120 Logo to the left of that adsense (instead of the Site Title which we type in Settings>General).

    (I think that's the only way i can have the header appear about 120px high and have logo on the left and adsense 728x90 ads to the right, yes?)

    So i guess it should look roughly like Geeksfolder posted in his lovely link above (reposting): http://postimage.org/image/tqiri7m95/
    So the yellow box from the screenshot represents the 728x90 AdSense, and i am trying to place my logo in the place of the left side Title.

    I have disabled the header image.

    I am using the Twenty Eleven theme.
    I have a basic Child Theme with Style.css and empty Functions.php in it (sorry if it is irrelevant, i am trying my best to learn and making progress, but i still have a long way to go!)

    Thank you very much for your help in advance.

  22. DomCasas80
    Member
    Posted 1 year ago #

    @Geekfolder - your code really works perfectly but I don't need the search form in my header just the google ads above my menu.. Could you help me?

  23. DomCasas80
    Member
    Posted 1 year ago #

    Nvm, I manage to remove the search form.

  24. aasbd
    Member
    Posted 1 year ago #

    Hello, I added adsense code to my site but ad are not displaying on the right side of header at top. Any problem there? Please help.
    http://www.aas-bd.com

Topic Closed

This topic has been closed to new replies.

About this Topic