Forum Moderators: phranque
I was told to use an “include” file, so instead of changing each add one by one I can do them all from the include file. Im confused, anyone know how I can make this work?
So does that mean I have to paste the include file code wherever I need the Adsense to appear?
I need help because I like to play around with the positions of the adsense, does that mean I have to go thought 100+ and change them manually? is it a necessary evil or there is an easier way?
They are in PHP pages. But I have 100+ pages of contents in PHP.If i wanted to change the color of the adsense ads, i currently need to do it by editing 100+ pages.
If they are written in PHP, I don't understand your problem.
Put (PHP properly formated) adsense code only in a file named say 'adsense.php'.
Remove the code itself from all of your pages and put this statement instead:
<?php
include 'adsense.php';
?>
Now, change only the file when you need it.
Maybe try something like
You can also load it into a variable and do the same thing:
Where "includes" is a directory where ad source code files are stored.
That's a php solution that won't cause parsing, or need "\"s in front of every line.
Good luck.
The point was not to treat the adsense code like a .php file, causing it to be parsed.
I hope this kind of url is ok per ToS, if not, I'm sure Jen will snip it out. It referred to a page of the php manual. Google "php manual include".
In all pages where I want an Adsense ad I put on the location of the ad the following code:
<?php include('_adsenseIncludes.php');?>
I use a _ for all my include files such as footers, headers, metatags etc so they are nicely grouped togheter in the top of my FTP client.
Then, in the _adsenseIncludes.php file I use if-statements to see what page I have, and then serve the Adsense code for that page. The next example I made for 3 types of pages. I have a page index.php, a group of pages that all start with widget-(thensomething).php and then the rest of the sites. To serve the Adsense codes I have soemthing like this in _adsenseIncludes.php:
<?php
//Adsense Includes
$ourOpenPage = $_SERVER['PHP_SELF'];
if (preg_match ("/^\/index.php/i", $ourOpenPage)) {
// Adsense code for the index page
?>
YOUR ADSENSE CODE
<?php }
elseif (preg_match ("/^\/widgets-.*/i", $ourOpenPage)) {
// Adsense for the widget-* pages
?>
YOUR ADSENSE CODE
<?php }
else {
// Adsense code for all other pages
?>
YOUR ADSENSE CODE
<?php }
?>
Note how I close and reopen the <php and?> PHP tags for each if-statement. This way you dont have to escape all the " etc in PHP but you can simply copy/paste the code exactly as Google gave you.
This code can also easily be adapted to make a single include file for example for metatags etc.
Hope this was usefull to at least one person =)
Adsense.php:
====================================
<?php
echo '
<SCRIPT type=text/javascript><!--
google_ad_client ...
...
//--></SCRIPT>
<SCRIPT
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"
type=text/javascript>
</SCRIPT>
';
?>
======================================================
YourPage.php:
======================================================
<html><header>....
....
<body>...
....
....
<?php
include 'Adsense.php';
?>
...
...
</body></html>
======================================================
Keep it simple.