Adding AdSense to Simple PHP Blog 
Wednesday, August 15, 2007, 01:57 AM
As you can see, AdSense is now available on my blog. See the ads on the upper-left corner of the site?

Signing up for AdSense is easy. Just head on over to www.google.com/adsense and register as a new user. Once you are approved, which may take up to 48 hours (much sooner in my case), you can begin adding AdSense code to your site.

To show the AdSense code in my site, I had to change three files included as part of the Simple PHP Blog installation. One of them, themes/modern/themes.php, was relatively simple to change. After the line:

echo( "\n<!-- SIDEBAR MENU BEGIN -->\n" );


I added the following:

//ADSENSE
theme_menu_block( menu_display_adsense(), "ADSENSE" );


This added the AdSense block to the very top of the sidebar. If you wanted to make it appear lower in the sidebar, simply move the above two lines of code wherever you want it to be placed.

The bulk of the changes occurred in the scripts/sb_themes.php file. I created a new function:

function menu_display_adsense() {
// Title: Adsense mod for sPhpBlog
// Author: Bill

// Returns adsense picture/script
global $lang_string, $user_colors;

$str = '<script type="text/javascript"><!--' . "\n";

// *** Make sure you use your own pub number here! ***
$str .= 'google_ad_client = "pub-xxxxxxxxxxxxxxxx";' . "\n";
// *** Make sure you use your own pub number here! ***

$str .= 'google_ad_width = 160;' . "\n";
$str .= 'google_ad_height = 600;' . "\n";
$str .= 'google_ad_format = "160x600_as";' . "\n";
$str .= 'google_ad_type = "text_image";' . "\n";
$str .= 'google_ad_channel = "";' . "\n";
$str .= 'google_color_border = "' . $user_colors[ 'menu_title_bg' ] . "\";\n";
$str .= 'google_color_bg = "' . $user_colors[ 'menu_bg' ] . "\";\n";
$str .= 'google_color_link = "' . $user_colors[ 'link_reg_color' ] . "\";\n";
$str .= 'google_color_text = "' . $user_colors[ 'menu_text' ] . "\";\n";
$str .= 'google_color_url = "' . $user_colors[ 'menu_title_text' ] . "\";\n";
$str .= '//-->' . "\n";
$str .= '</script>' . "\n";
$str .= '<script type="text/javascript"' . "\n";
$str .= ' src="http://pagead2.googlesyndication.com/pagead/show_ads.js">' . "\n";
$str .= '</script>' . "\n";
$result = array();
$result[ 'title' ] = $lang_string[ 'menu_adsense' ];
$result[ 'content' ] = $str;

return ( $result );
}

The nice thing about this function is the integration of the theme colors. This way, if you change the colors of your theme in the future, the AdSense colors will change to match your theme. Note: to find your pub number, use the AdSense site to generate some example code. You should see the pub number in the generated code.

Finally the last file I changed was languages/english/strings.php. I added a new line:

$lang_string['menu_adsense'] = "";

amongst the other $lang_string definitions found in the file. Note that there is nothing between the quotes. You could add a title to the AdSense block by adding one between the quotes, but I think it looks better with no text.

That's it! The modern theme should now automatically display AdSense ads when viewed. You should be able to change other themes using a similar process.

Bill
one of us is wrong 
Friday, October 24, 2008, 02:32 PM / http://www.oneofusiswrong.com
We made use of this code for our blog, www.oneofusiswrong.com, and it has been a nice addition to the site. Thank you for the information.
Andrew 
Thursday, April 24, 2008, 12:55 PM / http://www.andrewemmett.co.uk
Thank you very much for this advice, works a treat!

Would love to see an entry on your blog about how to put the adsense adverts in your specific blog entries as I've noticed you have done.

Again thanks for the advice, it was excellent.
loan payday 
Thursday, November 29, 2007, 08:46 PM / http://groups.google.com/group/lora7777 ... ayday-same
Hi. Day loan payday same Day loan no payday same teletrack Cash day loan payday same Day loan payday quick same Day faxless loan payday same Payday loan store Payday loan store milwaukee Payday loan store chicago Alabama loan payday store Payday loan store in chicago Same day no fax payday loan Savings account payday loan Account loan payday savings using Online savings account payday loan Faxless payday loan for savings account Payday loan with savings account only Payday loan in savings account Account into loan payday savings Account loan payday people savings No teletrack payday loan with savings account Low cost payday loan Faxless low cost payday loan Guaranteed payday loan Guaranteed no fax payday loan Bad credit guaranteed loan payday Guaranteed approval payday loan Guaranteed loan payday personal unsecured Payday loan with guaranteed no faxing Advance cash guaranteed loan payday 100 guaranteed payday loan Guaranteed faxless payday loan Guaranteed loan payday online Ten dollar payday loan Borrower dollar loan payday ten Quick cash payday loan Advance cash loan payday quick Cash loan payday quick utah Loan online payday quick Low fee payday loan Fee loan low online payday Low fee faxless payday loan Debt get loan payday Consolidation debt loan payday Fastest loan online payday Aafes loan payday Payday loan in georgia Georgia payday loan Fax georgia loan no payday Georgia loan online payday No fax payday loan in georgia Good work.

Comments 

Add Comment

Fill out the form below to add your own comments.









Insert Special: