WordPress.org

Ready to get started?Download WordPress

Forums

Editing post template (2 posts)

  1. sarahrussell
    Member
    Posted 6 years ago #

    The theme I'm using has a single post page (single.php). I use Adsense Deluxe and WP Ads on my site and I'd like to edit the theme so that the plugin calls (ie <!--adsense-->) are included automatically on each post. The goal is to be able to edit the ad placement on each post without having to edit all 450 posts by hand.

    Any help is appreciated!

  2. Adam Brown
    Member
    Posted 6 years ago #

    To append <!--adsense--> to the end of EVERY post that doesn't already have it, you can use this little piece of code. I haven't tested it, but it should work. Put it in one of these:

    1) Your theme's functions.php
    2) The end of the adsense deluxe or wp ads plugin file
    3) Into a blank PHP file, with a plugin header at the top of the file, and then activate it as a new plugin

    <?php
    function adsensify($content){
      if (false!==strpos($content,'<!--adsense-->'))
        return $content;
      return $content . "\n\n<!--adsense-->";
    }
    add_filter('the_content','adsensify',5);
    ?>

    Note that the <!--adsense--> thing won't show up when you edit posts--it gets appended right before the post gets displayed on your site.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags