The MU forums have moved to

Adsense WPMU Deployment - Prevent New Registration from removing code (8 posts)

  1. kenazar
    Posted 12 years ago #

    I need to deploy adsense code in my blog ASAP. I'm looking to have it on the primary domain and all subdomains when a new blogger signs up for a wp site. The only problem I'm having is protecting the plugin from new users and still having it active on there site. Can I deploy a pluging put my code in when they sign up and then remove their access to it while still active.

    I found this plugin but can't figure out how to write the code so the ads run below the hear and above & below the first post.


    Plugin Name: WordPress Adsense
    Version: 1.0
    Plugin URI:
    Description: Inserts Google Adsense inside your posts where you see fit.
    Author: William Long
    Author URI:

    function insert_adsense_code($data) {

    ** Replace this HTML code with your own customized Google Adsense code. **

    $adsense_code = '
    <!-- Begin Google Adsense code -->

    <div style="float: left;margin: 4px;">
    <script type="text/javascript"><!--
    google_ad_client = "pub-";
    google_ad_slot = "";
    google_ad_width = 300;
    google_ad_height = 250;
    <script type="text/javascript"

    <!-- End Google Adsense code -->

    ** All done! No more changes need to be made below this line! **

    if (is_single()) {
    return $adsense_code . $data ;
    } else {
    return $data ;

    add_filter('the_content', 'insert_adsense_code');


  2. andrea_r
    Posted 12 years ago #

    Like I said in the other thread - dump this plugin file in mu-plugins folder. Nobody can touch it then. It will be always on. It will not show up in the admin area. Users will not be able to remove it or disable it.

    The code above already places the ad at the end of the post.

  3. kenazar
    Posted 12 years ago #

    Hi Andrea,

    I got that, I need to have it above the first post, below and below the header and not sure how to do that with this code?

  4. andrea_r
    Posted 12 years ago #

    Go look in the codex for filters for those areas.

  5. kenazar
    Posted 12 years ago #

    Where do I go for that?


  6. andrea_r
    Posted 12 years ago #

  7. ancawonka
    Posted 12 years ago #

    When you're reading the codex, focus on the add_filter function - that's what's placing the adsense code where it shows up today.

    Something else I found helpful is, which explains how to use hooks to insert your "stuff" in various pre-specified places in the code.

  8. kenazar
    Posted 12 years ago #

    Thanks I'll take a look.


About this Topic