Sticky Footer and header Ads for Free Sites

Hello.

I have Pro Sites isntalled in my multisite network.

I want free sites and teh first level in Pro Sites to have a sticky footer ad and a stiky header ad (they will change depending on screen resolution).

I tried using the build in ads section in Pro Sites, but it only displays ads in single post/page and not in the home page.

My idea is to use Custom footer and custom header text from Ultimate Branding to create the ads, and create a plugin that removes those ads that will be available at the desired Pro Sites Level.

What do you think about this idea?

The only problem I have is that I dont know how to create that plugin ;(. Could you help me?

Thank you!

  • Michael Bissett

    Hi @Carlos Divas, hope you're doing well this evening! :slight_smile:

    The idea you mentioned would take a fair amount of custom coding to implement, I would like to ask though, when you say this:

    I tried using the build in ads section in Pro Sites, but it only displays ads in single post/page and not in the home page.

    Is this only taking place on a certain site? And is this only taking place with a certain theme active?

    Could you enable Support Access to your Multisite, so that we can have a closer look at things here?

    Please advise,
    Michael

  • Ash

    Hello @Carlos

    I hope you are well today.

    Please use the following code:

    add_action( 'wp_head', 'set_ad_for_free_level' );
    function set_ad_for_free_level() {
        if( ! is_user_logged_in() ){
            global $psts, $blog_id;
    
            $header = "<div id='pro_header_ad'>Header</div>";
            $footer = "<div id='pro_footer_ad'>footer</div>";
    
            $expire = $psts->get_expire( $blog_id );
            if( ! $expire ){
                echo $header . $footer;
            }
            ?>
            <style>
                body{position: relative;}
                #pro_header_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; top: 0; left: 0; position: fixed; background: #fff; text-align: center; border-bottom: 1px solid #000; }
                #pro_footer_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; bottom: 0; left: 0; position: fixed; background: #fff; text-align: center; border-top: 1px solid #000; }
            </style>
            <?php
        }
    }

    You can add those codes in mu-plugins. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Make sure you add the ad code in $header and $footer variable.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

    • Carlos

      Hello Ash.

      Thank you for your help.

      I erased the code from the footer content and header content, then created the mu-plugins folder, and added this code to a file called ads.php:

      add_action( 'wp_head', 'set_ad_for_free_level' );
      function set_ad_for_free_level() {
          if( ! is_user_logged_in() ){
              global $psts, $blog_id;
      
              $header = "<div id='pro_header_ad' style='text-align: center;
      position: fixed;
      width: 181px;
      top: 0;
      right: 50px;
      background: grey;
      color: white;
      z-index:999999;'><p>¡Crea un Sitio 502!</p></div>";
      
              $footer = "<div id='pro_footer_ad' style='text-align: center;background-color: #565656;
      height: 50px;
      margin:0px;
      overflow: hidden;
      position: fixed;
      bottom: 0;
      width: 100%;'>
      
      <h3><span style='color: #ffffff;'>Este Sitio Fue Creado Usando http://www.502.gt.  Crea Tu Página Web Gratis >></span></h3></div>";
      
              $expire = $psts->get_expire( $blog_id );
              if( ! $expire ){
                  echo $header . $footer;
              }
              ?>
              <style>
                  body{position: relative;}
                  #pro_header_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; top: 0; left: 0; position: fixed; background: #fff; text-align: center; border-
      
      bottom: 1px solid #000; }
                  #pro_footer_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; bottom: 0; left: 0; position: fixed; background: #fff; text-align: center; border-
      
      top: 1px solid #000; }
              </style>
              <?php
          }
      }

      But I get this error:

      Parse error: syntax error, unexpected '}' in /home2/cdivas2/0SitiosWeb/T/TLC/5librasPrueba/wp-content/mu-plugins/ads.php on line 37

      http://salud2.pierde5librasen5dias.com/

      Some questions about this code:

      1. Will it display ads only for free sites? Or can I choose the Pro Sites level where they start to disable?

      2. They will not see the ads if they are logged in, correct?

      Thank you for your help Ash! :wink:

  • Ash

    In that case, please try the following code:

    add_action( 'wp_head', 'set_ad_for_free_level' );
    function set_ad_for_free_level() {
        if( ! is_user_logged_in() ){
            global $psts, $blog_id;
    
            $header = "<div id='pro_header_ad' style='text-align: center;
    position: fixed;
    width: 181px;
    top: 0;
    right: 50px;
    background: grey;
    color: white;
    z-index:999999;'><p>¡Crea un Sitio 502!</p></div>";
    
            $footer = "<div id='pro_footer_ad' style='text-align: center;background-color: #565656;
    height: 50px;
    margin:0px;
    overflow: hidden;
    position: fixed;
    bottom: 0;
    width: 100%;'>
    
    <h3><span style='color: #ffffff;'>Este Sitio Fue Creado Usando http://www.502.gt.  Crea Tu Página Web Gratis >></span></h3></div>";
    
            $level = $psts->get_level( $blog_id );
            if( (int) $level < 2 ){
                echo $header . $footer;
            }
            ?>
            <style>
                body{position: relative;}
                #pro_header_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; top: 0; left: 0; position: fixed; background: #fff; text-align: center; border-
    
    bottom: 1px solid #000; }
                #pro_footer_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; bottom: 0; left: 0; position: fixed; background: #fff; text-align: center; border-
    
    top: 1px solid #000; }
            </style>
            <?php
        }
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

    • Ash

      Try this:

      add_action( 'wp_head', 'set_ad_for_free_level' );
      function set_ad_for_free_level() {
          if( ! is_user_logged_in() ){
              global $psts, $blog_id;
              $special_blogs = array( 21, 15, 19, 32 );
              if( in_array( $blog_id, $special_blogs ) ){
                  $header = "<div id='pro_header_ad' style='text-align: center;
                              position: fixed;
                              width: 181px;
                              top: 0;
                              right: 50px;
                              background: grey;
                              color: white;
                              z-index:999999;'><p>¡Crea un Sitio 502!</p></div>";
      
                  $footer = "<div id='pro_footer_ad' style='text-align: center;background-color: #565656;
                              height: 50px;
                              margin:0px;
                              overflow: hidden;
                              position: fixed;
                              bottom: 0;
                              width: 100%;'>
                              <h3><span style='color: #ffffff;'>Este Sitio Fue Creado Usando http://www.502.gt.  Crea Tu Página Web Gratis >></span></h3></div>";
      
                  $level = $psts->get_level( $blog_id );
                  if( (int) $level < 2 ){
                      echo $header . $footer;
                  }
                  ?>
                  <style>
                      body{position: relative;}
                      #pro_header_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; top: 0; left: 0; position: fixed; background: #fff; text-align: center; border-
      
          bottom: 1px solid #000; }
                      #pro_footer_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; bottom: 0; left: 0; position: fixed; background: #fff; text-align: center; border-
      
          top: 1px solid #000; }
                  </style>
                  <?php
              }else{
                  $header = "<div id='pro_header_ad' style='text-align: center;
                              position: fixed;
                              width: 181px;
                              top: 0;
                              right: 50px;
                              background: grey;
                              color: white;
                              z-index:999999;'><p>ADD TEXT FOR SPECIAL BLOGS</p></div>";
      
                  $footer = "<div id='pro_footer_ad' style='text-align: center;background-color: #565656;
                              height: 50px;
                              margin:0px;
                              overflow: hidden;
                              position: fixed;
                              bottom: 0;
                              width: 100%;'>
                              <h3><span style='color: #ffffff;'>ADD TEXT FOR SPECIAL BLOGS</span></h3></div>";
      
                  echo $header . $footer;
                  ?>
                  <style>
                      body{position: relative;}
                      #pro_header_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; top: 0; left: 0; position: fixed; background: #fff; text-align: center; border-
      
          bottom: 1px solid #000; }
                      #pro_footer_ad{width: 100%; padding: 10px 20px; box-sizing: border-box; bottom: 0; left: 0; position: fixed; background: #fff; text-align: center; border-
      
          top: 1px solid #000; }
                  </style>
                  <?php
              }
          }
      }

      You need to change the IDs in $special_blogs array and change the content in lower block.

      Let us know if it works :slight_smile:

      Cheers
      Ash

  • Carlos

    Ash! You really rock man! It works like a charm.

    I have one more question for this.

    I am using New Blog Template plugin. I am using the "display templates in page" option. The main idea is to display an ad for template demos with a link to "activate this template" (that is the special ad for the special blog ids).

    How do I create a link that redirects users to the registration page with that current blog ID as a template already selected?

    Thank you!

  • Ash

    Hello @Carlos Divas

    It's maybe possible, but I can't confirm. Also, it will depends on how you set the NBT settings. If you send me admin and ftp login, I can give it a try.

    To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question
    Subject: Attn-Ash
    Details: Send all required details (admin info and/or ftp details) with a link of this thread, so that I can track.
    Also post a note here once you send the info.

    I will be happy to take a look :slight_smile:

    Cheers
    Ash

  • Carlos

    Hello Ash! Thank you for your help.

    It is looking great. I have some questions though:

    1. Can I use a different style if it is a "normal ad" or if it is a "template ad"? Because when using Template Ads I need to put a margin to the body that should not go when using the Normal Ads.

    2. I do need to be able to display de templates in a showcase page. Eventually they will be too many to show in the registration form.

    I saw that the link with this method uses the "?blog_template=1" where the number of the template ID is different from the blog Id.

    I was thinking that the link could be created using two arrays. One with the Special Blog Ids, and anotherone with the correponding Template Ids.

    Even if I have to update those arrays manualy when I add new templates :wink:

    Do you think this is possible?

    Thank you!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.