WordPress.org

Forums

Add adsense after more tag only on post (9 posts)

  1. dudd, médecine blog
    Member
    Posted 4 years ago #

    Hi,

    Please how can i Add adsense code after the more breaking tag only on post (no on page or category)

    thank's

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Add the adsense code to your theme's single.php file only.

  3. dudd, médecine blog
    Member
    Posted 4 years ago #

    yes, but how to display after the more tag ?

  4. alchymyth
    Forum Moderator
    Posted 4 years ago #

    in single.php, instead of the_content(); try to use:

    $story = get_the_content();
    $story = explode('<span id="more',$story);
    $first_part_of_story = $story[0];
    $second_part_of_story = $story[1];
    $first_part_of_story = apply_filters('the_content', $first_part_of_story);
    echo $first_part_of_story;
    if ($second_part_of_story) {
       echo 'here adsense code';
       $second_part_of_story = explode('</span>',$second_part_of_story);
       $second_part_of_story = apply_filters('the_content', $second_part_of_story[1]);
       echo $second_part_of_story;
    } ;
  5. dudd, médecine blog
    Member
    Posted 4 years ago #

    thank's alchymyth it work

  6. Andrew Smith
    Member
    Posted 4 years ago #

    Useful code... :-)

  7. jenseo
    Member
    Posted 4 years ago #

    Hey!

    I'm using this code on one of my websites, but I'm having a problem. When I use plugins that adds something to the bottom of my post, it shows in the bottom of the post, but also after the more tag (in the middle of the post).

    Is there someway to modify this code to prevent that from happening?

    Thanks!
    // Jens.

  8. alchymyth
    Forum Moderator
    Posted 4 years ago #

    try this new approach - without the need to edit single.php - i.e. leave the_content() as it is:

    it uses a filter function (http://codex.wordpress.org/Plugin_API/Filter_Reference) and pops the ad code right into the more span in single post:

    http://wordpress.pastebin.com/vGuWG7Hp

  9. jenseo
    Member
    Posted 4 years ago #

    Thanks a lot, that's perfect!

Topic Closed

This topic has been closed to new replies.

About this Topic