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;)
I have tried this but it gives me 500 internal server error