1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Adding Affiliate ads to a wordpress site

Discussion in 'Blogging' started by mickeylove, Aug 8, 2011.

  1. mickeylove

    mickeylove Registered Member

    Joined:
    Jul 26, 2011
    Messages:
    55
    Likes Received:
    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
     
  2. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    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');
     
  3. mickeylove

    mickeylove Registered Member

    Joined:
    Jul 26, 2011
    Messages:
    55
    Likes Received:
    2
    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!
     
  4. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    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
     
  5. agnosticon

    agnosticon Jr. VIP Jr. VIP Premium Member

    Joined:
    Feb 6, 2009
    Messages:
    520
    Likes Received:
    1,088
    Location:
    Mars
    edit your theme files
     
  6. mickeylove

    mickeylove Registered Member

    Joined:
    Jul 26, 2011
    Messages:
    55
    Likes Received:
    2
    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!
     
  7. VIC SEO

    VIC SEO Elite Member

    Joined:
    Feb 19, 2010
    Messages:
    2,156
    Likes Received:
    363
    Gender:
    Male
    Occupation:
    SEO Specialist
    Location:
    iSynergyMedia
    Home Page:
    I agree with Autumn, my developers do the same thing whenever they need to customize a theme. Nice pic Autumn.