Adding Affiliate ads to a wordpress site

mickeylove

Registered Member
Joined
Jul 26, 2011
Messages
54
Reaction score
2
Hi guys,

Still plugging away at my WP site.

Working to insert custom html code into the entire site.

The ads I have use html absolute positioning to 'stick' to the left and right sides of the screen. Then use the pixels from top method to add 150px to each ad (ads are all 150px x 150px squares)

I would like a way to add this code into all of the pages in my site/blog.

Is there a way to do this? - Haven't found any good plugins that will do it.

Am I missing something?

Thanks
 
Easiest way is to edit the theme files in wp-content/themes/your-theme-name. You will want to edit index.php, single.php and any other pages that you want to place ads in.

You can either hardcode your ad html into your themes or you can use a php include, eg. put the html for your ad in a file called ad1.html and then include it in the WP theme in the relevant spot using something like

Code:
include('ad1.html');
 
Thanks very much.

I've edited my index.php and single.php

added the code at the very beginning.

Doesn't seem to work on the site - I put the ad1.html in the usual place, uploaded with cpanel to my public_html as I would the index.html

This didn't work, so I also put the ad1.html in the same directory as my edited php files. Still no joy.

When I visit mysitecom/ad1.html it is there.

Anyone have any hints to get me there?

Thanks Autumn for your help!
 
Make sure:

* you put opening and closing tags around your php include:
Code:
<?php include('ad1.html'); ?>

* the path to ad1.txt is correct - try using the absolute path to the file on the server file system which might look something like /home/yourusername/www.yourdomain.com/public_html/ads1.html (I would recommend putting your ads files in a new directory to keep everything neat and tidy).

* you can get the current directory that your wordpress install is in by using:
Code:
<?php
$dir = getcwd();
echo "Current directory: $dir";
?>

* the include statement goes in the spot where you want the ad to appear within the <body> tag
 
Thank you both so much!

After much faffing around with absolute links (my structure is non standard)

I used:

<?php include('ad1.html'); ?>

Where ad1.html is located: /public_html/blog/wp-content/themes/striking

I'm really happy, despite it not working fully as my header bar is over a couple of my ads. Something to work on.

Another small success for me. Thanks again!
 
I agree with Autumn, my developers do the same thing whenever they need to customize a theme. Nice pic Autumn.
 
Back
Top