Home > AdSense, Wordpress > How To Put Google AdSense Link Unit on a Wordpress Theme Header

How To Put Google AdSense Link Unit on a Wordpress Theme Header

In this article we are going to discuss how to put Google AdSense Link Unit on a Wordpress Theme header so that it mimics a top menu or sub menu of the theme. As you may already know, putting Google AdSense advertising on websites or blogs should be done in such way that the advertising box is perfectly “blended” in the page, so that the visitors would think that it was not an advertising.

In the case of Link Unit, it should be placed near the menus, whether it is main menu on the top of the page, left menu, or right menu. Some people also suggests that we place the Link Unit near a search box.

It’s assumed that you already have an account on Google Adsense (click here if you have not) and a blog on self hosted Wordpress. The simple 2 steps technique described here can also be applied on any website or blog since we are going to modify (a little bit) the HTML code of the theme.


1. Create AdSense Link Unit

First step, you need to obtain the Adsense Link Unit code to be embedded to your theme. Log in to your Google AdSense account, and click on AdSense Setup tab then Get Ads link.

Get Adsense Link Unit

Select Link unit since we are about to create one. Click Continue button.

Link Unit Properties
Next you choose the ad format.

  1. Select the size of the ads and number of ads link in this unit
  2. Select the color for the ads to match it to your theme color

Click Continue button.

Set Ads Channel

Next, you optionally choose the Ad Channels. Channels are grouping for all ads for analysis purpose. For example you have several AdSense units in your site and you want to track which unit is generating revenue most. By defining channel you can track that information and then optimize the ads grouped on that channel. You can skip this step anyway. Click Continue button.

 

Set Unit name

Next, you set the name for this ads. Type a name that identify the purpose or placement of this ads. Then finally, click the Submit and Get Code button to get the ads code.

Get the code

There your ads code are. Copy the code, we are going to paste it to a theme that we need to place the link on.

2. Modify Theme

Now, login to you Wordpress admin account. Click on the menu Appearance (on the left side of the page) – Editor. This will bring you to the current theme file editor.

WP Theme Editor Menu

The theme editor will show up:

WP the theme file editor

Here we can modify many aspect of our current theme like colors, size, layout, etc. You can select other theme than the current theme by selecting the theme to edit list box on the top right of the page.

In this example we are going to modify the Header file which is a PHP file that defines the header section of the theme. Select Header (header.php) on the right side of the page. Then the file editor the the header.php file will show up.

WP edit the header.php file

The file was basically a plain PHP file with HTML codes inside. Let’s take a look at it:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo(’html_type’); ?>; charset=<?php bloginfo(’charset’); ?>" />
<title><?php bloginfo(‘name’); ?><?php wp_title(); ?></title>
<meta name="generator" content="WordPress <?php bloginfo(’version’); ?>" />
<link rel="stylesheet" href="<?php bloginfo(’stylesheet_url’); ?>" type="text/css" media="screen" />
<link rel="shortcut icon" type="image/ico" href="<?php bloginfo(’stylesheet_directory’); ?>/images/favicon.ico" />
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo(’name’); ?> RSS Feed" href="<?php bloginfo(’rss2_url’); ?>" />
<link rel="pingback" href="<?php bloginfo(’pingback_url’); ?>" />
<?php wp_head(); ?>
</head>

<body>

<div id="page">
    <div id="header">
        <div class="header_wrapper">
            <div class="header_left">
                <h1><a href="<?php bloginfo(’url’); ?>"><?php bloginfo(‘name’); ?></a></h1>
                <h2><?php bloginfo(‘description’); ?></h2>
            </div>
           
            <div class="header_right">
                <ul>
                <li<?php if(is_home()&amp;&amp;!is_paged()) echo ‘ class="current_page_item"’; ?>><a href="<?php bloginfo(’url’); ?>">Home</a></li>
        <?php wp_list_pages(‘title_li=&amp;depth=1′); ?>
                </ul>
            </div>
        </div>
    </div>

The <head> section is the HTML header for the theme, skip that as it is. Take a look on the <div> tag with ID “header”. This is the div that contains the header layout. We are going to add our AdSense code inside it. Just before the closing tag of this div, put this code (the one that we got from AdSense setup, but surrounded by a new div tag with some style to match the whole theme colors):

<div style="padding:3px;background-color:#2D6E89">
  <script type="text/javascript"><!–
  google_ad_client = "pub-7773800616131770";
  /* dijexi-link-top */
  google_ad_slot = "9510052288";
  google_ad_width = 728;
  google_ad_height = 15;
  //–>
  </script>
  <script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
  </script>
</div>
 

Save the file by pressing the Update File button. To revise, your new header.php file will looks like this:

WP Updated header.php file

You are done!

Now, take a look on the new theme with an AdSense Link unit inserted just below the header which looks like a sub menu of our page (can you find it? :-) ).

WP Theme updated with a Google Adsense link Unit as submenu

That’s all for now, next time we will discuss about using AdSense in FeedBurner. Leave me a comment of you have something to discuss.

Technorati Tags: ,,

Akhmad Daniel Sembiring

vITraining.com – Qualified IT Products, Outsourcing, and Services

Ligarwangi.com – Linux, E-book, Coffee, Gift, etc

 

Reblog this post [with Zemanta]

  • Share/Bookmark
Categories: AdSense, Wordpress Tags: , ,
  1. November 15th, 2009 at 19:59 | #1

    thank you man, its was a nic reed! :-)
    v

  2. November 24th, 2009 at 00:25 | #2

    An expert is a person who has made all the mistakes that can be made in a very narrow field.

  3. January 24th, 2010 at 12:47 | #3

    I enjoyed reading this

  4. February 9th, 2010 at 20:23 | #4

    Doesn’t work for me. I’m using a Garland theme.

    The box appears but it is “dead” — the cursor won’t even register if I click in the box.

    Still trying to debug this.

  5. February 14th, 2010 at 15:26 | #5

    i am really very thankful that Google launched the Adsense program. this enables most of us who owns several websites to work at home.

  6. March 4th, 2010 at 22:32 | #6

    i love google Adsense, it enables me to earn money on the websites and forums that i have put up several years ago. if you got tons of websites, you can earn a lot from Adsense alone

  1. No trackbacks yet.
This site uses a Hackadelic PlugIn, Hackadelic SEO Table Of Contents 1.6.0.