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

Need help with a code

Discussion in 'General Programming Chat' started by black101, May 11, 2013.

  1. black101

    black101 Supreme Member

    Joined:
    Dec 2, 2010
    Messages:
    1,440
    Likes Received:
    1,613
    Location:
    Switzerland
    im trying to have a adsense before all my post, i have manage to do it, but i want it to display in the middle, can someone help

    i have pasted this code into the function.php

    <?php
    function bfa_add_adsense($post_body_content) {
    $adsense_ad = '<div class="bfa-adsense">
    ADSENSE
    CODE
    HERE
    </div>';
    if ( is_single() ) {
    if (strpos($post_body_content,'%adsense%')!==FALSE) {
    $post_body_content = str_replace('%adsense%', $adsense_ad, $post_body_content);
    } else {
    $post_body_content = $adsense_ad . $post_body_content;
    }
    }
    return $post_body_content;
    }
    add_filter('the_content', 'bfa_add_adsense');
    ?>
     
  2. Subsonic

    Subsonic Regular Member

    Joined:
    Mar 17, 2011
    Messages:
    367
    Likes Received:
    333
    Location:
    DNS root zone database
    Depending on your ad width use the following css:

    Code:
    .bfa-adsense {
    width: 250px
    margin-left: auto;
    margin-right:auto;
    }
    Just change the width to suit your needs. You could do it with jQuery too, but this is simpler.
     
    • Thanks Thanks x 1
  3. black101

    black101 Supreme Member

    Joined:
    Dec 2, 2010
    Messages:
    1,440
    Likes Received:
    1,613
    Location:
    Switzerland

    thanks man
     
  4. moijeishaianu

    moijeishaianu Newbie

    Joined:
    Jun 28, 2013
    Messages:
    15
    Likes Received:
    0
    hmm, why dont adding it in plain javascript