Support » Theme: .TUBE » Adding ads banners to left and right on single post?

  • Resolved vpbay

    (@vpbay)



    Hi
    I would like to add advertisement banners to left and right of single post . How to do that?

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Theme Author tubegtld

    (@tubegtld)

    Assuming you’re using a child theme, one approach would be to create a custom template.

    1) copy the single.php file from the main theme into your child theme.

    2) (optional) rename it to only apply to a specific post type (e.g. single-post.php)

    3) customize the template to include your ads

    If you’d like to do it programmatically, you can hook into ‘tube_content_top’ and ‘tube_content_bottom’ to wedge in some custom <divs>, and filter ‘tube_filter_content_columns’ to make sure it’s full width.

    Here’s tested code you drop in your child theme’s functions.php file or in a plugin…

    add_action( 'template_redirect', 'my_tube_maybe_show_ads' );
    
    function my_tube_maybe_show_ads(){
      
      if ( ! is_singular( 'post' ) ) return;
    
      add_action( 'tube_content_top', 'my_tube_left_ad' );
      add_action( 'tube_content_bottom', 'my_tube_right_ad' );
      add_filter( 'tube_filter_content_columns', 'my_tube_content_columns' );
    
    }
    
    function my_tube_left_ad(){
    
      ?>
      <div class="row">
      <div class="col-md-2">LEFT AD HERE</div>
      <div class="col-md-8">
      <?php
    
    }
    
    function my_tube_right_ad(){
    
      ?>
      </div><!-- .col-->
      <div class="col-md-2">RIGHT AD HERE</div>
      </div><!-- .row -->
      <?php
    
    }
    
    function my_tube_content_columns(){
    
      return 'col-xs-12';
    
    }
    Theme Author tubegtld

    (@tubegtld)

    Almost forgot… please mark as resolved if this solves your issue, and if you’re enjoying the theme, please leave a review.

    Thanks but I dont want to show in mobile. How to discard mobile?

    • This reply was modified 1 year, 2 months ago by  vpbay.

    It looks bad in mobile. So the best way is disabling this code in mobile.

    DELETED

    • This reply was modified 1 year, 2 months ago by  toddlevy.
    Theme Author tubegtld

    (@tubegtld)

    You can do that with Bootstrap CSS classes on the various columns.

    NOTE: May inflate your impression numbers.

    add_action( 'template_redirect', 'my_tube_maybe_show_ads' );
    
    function my_tube_maybe_show_ads(){
      
      if ( ! is_singular( 'post' ) ) return;
    
      add_action( 'tube_content_top', 'my_tube_left_ad' );
      add_action( 'tube_content_bottom', 'my_tube_right_ad' );
      add_filter( 'tube_filter_content_columns', 'my_tube_content_columns' );
    
    }
    
    function my_tube_left_ad(){
    
      ?>
      <div class="row">
      <div class="hidden-xs hidden-sm col-md-2">LEFT AD HERE</div>
      <div class="col-xs-12 col-sm-12 col-md-8">
      <?php
    
    }
    
    function my_tube_right_ad(){
    
      ?>
      </div><!-- .col-->
      <div class="hidden-xs hidden-sm col-md-2">RIGHT AD HERE</div>
      </div><!-- .row -->
      <?php
    
    }
    
    function my_tube_content_columns(){
    
      return 'col-xs-12';
    
    }
    • This reply was modified 1 year, 2 months ago by  tubegtld.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding ads banners to left and right on single post?’ is closed to new replies.