Friday, November 24, 2017

How to add Google adsense code in PHP file?

google adsense logoIf you have tried to show Google adsense code inside any PHP file, you know that's not easy. PHP code directly can not interpret adsense code. So, the solution is you assign the adsense code to a variable and show the value of variable where you want to show ad. Check out the example below.

This is the code you need to put in your PHP file. Be sure, to change your publication id mention as pub-xxxxxxxx inside the code. Also, the width and height of ad as per rules of Google adsense ads type.

//assign adsense code to a variable
$googleadsensecode = '
';


Now, just add the below code wherever you want to show your ad

echo $googleadsensecode;

Simple.

No comments:

Post a Comment

4.5 out of 5 stars Reviewer:adminFebruary 05, 2021