Manually add Adsense in wordpress header


Hope you guys are having an awesome day or night, in today article I would like to demonstrate a powerful technique in WordPress of how to add Adsense in the WordPress header or Just high above the fold of your website. This can be particularly helpful in optimizing your Adsense ad placement. We will also demonstrate how to prevent said Adsense ads from appearing on pages that you don’t want it to which is great for remaining in line with Adsense terms of service.

wordpress header

It’s also important to note that while this will work with Adsense banner ads, it also applies to other networks such as Amazon banners and even Google custom search box.You could probably find software to do this but none will give you the control as being able to place the ads in by yourself manually.

 

How to add Adsense in WordPress header Manually?

 

Log into the WordPress dashboard of your website and go to:

1. Appearance and then select Editor.

2. In the right panel select Header (header.php)

3. Now in the windows scroll down and find: </header>

 

wordpress header

Place Adsense in website header

4. You may now copy and paste your Adsense code before or after head tag.

5. Update or save the file and your header should have a flashy new banner.

 

Center Your Adsense Ad unit

 

To center the Ad unit you will need to add the following before or after pasting the code into the WordPress header.php file:

<div align=”center”>Place Adsense code here</div>

You could also align it to any side by replacing center with right or left.

 

Exclude Adsense From Selective Pages on your WordPress Blog

 

This can be very tricky when you are working with HTML and editing the header.php file in WordPress But you can create a customizable rule to allow the Adsense Ad unit from appearing on Pages that you do not want it to appear on.  This can be very good for prevent Ads from appearing on Contact, Privacy Policy or About pages of your Blog which if you do not know is against the Adsense Terms of Service and if you are caught violating these rules you could have your account banned, so here’s what to do to prevent the ads from appearing on pages you do not want.

Simply add the following code with you centered Adsense Ad unit, replace the areas in Green and red with your Page title or Post ID to exclude the banner from the pages or post that you do not want it to appear on this is ideal for controlling when and where your Ad units appear:

 

<?php if (!is_page(array(‘Place Page name here‘, ‘Place Page name here‘, post ID, Post ID))) { ?>

Adsense code goes here

<?php } ?>

 

How to find the post ID of a WordPress Post or Page?

 

Finding the post ID’s have become a little tricky in WordPress but they are still there, to find the post ID of any Page or article simply go to the All post screen or Pages screen in WordPress and hover your mouse over the title of the Page or article and look in the lower left hand corner of the screen you should see a file path or URL appear in the lower left of the screen. You will also notice that it will say:

Post = then a number   or

ID= then a number

The number there is your post ID and its unique for every Page, category or post on your Blog. So simply find the pages you want to prevent Adsense from being displayed on and get the ID’s and simply add them to the code above.

 

I hope this article was helpful in helping you Manually Place a regular banner or Adsense Banner in the header of your Website or Blog which can be great for optimizing your Adsense Ads.  If this was helpful please take the time to leave a comment it would be great to hear from you our readers.

 


About Ricardo Gardener

I am a Technology enthusiast and a Blogger who loves nothing more than playing with new exciting Gadgets and technology. In my spare time I repair and maintain computers, which is just a few of my many hobbies. Please feel free to leave a comment below and subscribe to this blog. Thank you very much for your visit.

:) How well did I do? Take a moment to leave a comment.