Right Way to Add Google Adsense Code in PHP Script

There is no doubt on Google Adsense which is the famous and the best publisher network. Mostly while blogging Adsense is used as main income source by showing ads units and the blog owners are making some money through it. So for that you need to implement Adsense code properly in your blog or any website. So some blogging platforms like Blogger, WordPress, Hubpages, Webbly, WordPress, Yola and other sites are very simple to add Adsense codes. But once you go for self hosted sites like WordPress Content Management System in short CMS or PHP script whatever may be there the problem arises.

Add Google Adsense Code Properly in PHP Script Used Sites?

In self hosted sites, the ad units should be added manually and it won’t accept HTML/JavaScript codes. But HTML and Javascripts code can fit for blogger and others sites. So in need to add Adsense units on PHP scripts you need to make some modification on the script provided by Google Adsense. You can also find various available plugins for WordPress. So it make easy for WordPress sites too! Now the issues is only for PHP scripted sites.

Check it: Google Adsense vs Affiliate Program: Which Helps you to Make HUGE Money?

So to help you out, this post can guide you to Insert Google Adsense Code Properly in PHP Script. Lets check it out,

Insert Google Adsense Code in PHP Script Used Sites

The normal Adsense code looks like,

<script type=”text/javascript”>
google_ad_client = “PUBLISHER ID”;
google_ad_slot = “8180665601”;
google_ad_width = 728;
google_ad_height = 90;
</script>
<!– AD NAME –><script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>

So to change this code to PHP variable and then outputting to an HTML as follows,

<?php
//assign adsense code to a variable
$googleadsensecode = ‘
<script type=”text/javascript”>
google_ad_client = “PUBLISHER ID”;
google_ad_slot = “8180665601”;
google_ad_width = 780;
google_ad_height = 90;
</script>
<!– AD NAME –><script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>’;
//now outputting this to HTML
echo $googleadsensecode;
?>

Check it: What Google’s Optimizing AdSense Online Course has Taught me?

Hope you added successfully to your site without facing any issues. If you’re facing any problems then share with us in comments. Do likes and share this post with your friends! Cheers;)

Facebook Comments

Speak Your Mind

*

CommentLuv badge