1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to put an adsense automatically at the bottom of each wordpress post

Discussion in 'WordPress' started by mpak11, Jan 25, 2011.

  1. #1
    I am using the all in one adsense plugin for a 336 x 280 ad format....however, I also want to add adsense at the end of each post, but can't do this with the plugin since it only allows for one ad format....

    For now, the only option I know is to manually add the adsense code at the bottom of the post ....

    Is there an easier way, like putting the code somewhere so it would automatically appear at the bottom of each post? I am thinking of a 460 x 80 at the bottom of each post.
     
    mpak11, Jan 25, 2011 IP
  2. teamnirvana

    teamnirvana Active Member

    Messages:
    844
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Use "Add Post Footer" wordpress plugin. Copy and paste your adsense code in it. Use <table> to get a better view.
     
    teamnirvana, Jan 25, 2011 IP
  3. aap

    aap Well-Known Member

    Messages:
    1,802
    Likes Received:
    39
    Best Answers:
    2
    Trophy Points:
    120
    #3
    you can edit single.php file of your theme.
     
    aap, Jan 25, 2011 IP
  4. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes. I suppose you could do that. There is a more elegant method, and one that the plugins use (who needs another plugin, right?)

    In your theme functions.php:

    
    /* Filter the_content() */
    add_filter( 'the_content', 'my_content_filter' );
    
    function my_content_filter( $content ) {
       if ( is_single() || is_page() ) {
          $content .= 'insert your code between these single quotes';
       }
       return $content;
    } 
    
    Code (markup):
    This code will attach your Google AdSense Block to the end of single posts and pages. Additional conditional statements could be added to place the code onto the page, and not just at the end. You can add it before, after, or with a little bit of Php, in the middle somewhere.
     
    Dodger, Jan 26, 2011 IP
  5. rozer82

    rozer82 Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    open single.php and put your google adsense script
     
    rozer82, Jan 26, 2011 IP
  6. freshtutorialdotcom

    freshtutorialdotcom Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can use quick adsense plugin. with which you can insert add on button, top and also in middle of every post with different option
     
    freshtutorialdotcom, Jan 26, 2011 IP
  7. GamesPond

    GamesPond Well-Known Member

    Messages:
    763
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    130
    #7
    Yes single.php is easy to edit. Just go to themes editor and click single.php then put your adsense code where you need it. Always make a backup of any changes you make when in the editor.
     
    GamesPond, Jan 27, 2011 IP
  8. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This is not the right way to add the code. You add the code with a filter as I described a few posts back. This is the same technique that plugins use, and it does not mess with your template files to do it.

    With filters, you can prepend the post or page, append the post or page, and with a few lines of Php you can put the ad block right after the 2nd paragraph if you wish.

    With filters, you can specify a priority when your filter will fire. Let's say you want your ad above all other plugins before they fire, then you specify a higher priority. If you go the route of editing single.php, you can only get the ad in one place -- after all other plugins have done their dirty deed to the_content().
     
    Dodger, Jan 27, 2011 IP