• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Collapsible Div Tags for Google Ads

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Collapsible Div Tags for Google Ads

This topic is: not resolved

Tagged: Collapsible Div Tags

  • This topic has 4 replies, 2 voices, and was last updated 11 years, 5 months ago by Brad Dalton.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • April 6, 2015 at 8:12 pm #146866
    CJWheels
    Member

    This is an odd one that has me stumped. I have a client running Google Ads. They have mobile ads that do not show up unless on mobile. The problem is, they still take up space on desktop browsers. The Google Ad contact keeps referring us to this page: https://support.google.com/dfp_sb/answer/3419382?hl=en

    I have it placed in the <head> script:
    <script type='text/javascript'>
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    (function() {
    var gads = document.createElement('script');
    gads.async = true;
    gads.type = 'text/javascript';
    var useSSL = 'https:' == document.location.protocol;
    gads.src = (useSSL ? 'https:' : 'http:') +
    '//www.googletagservices.com/tag/js/gpt.js';
    var node = document.getElementsByTagName('script')[0];
    node.parentNode.insertBefore(gads, node);
    })();
    </script>

    <script type='text/javascript'>
    googletag.cmd.push(function() {
    googletag.defineSlot('/50217444/Momsnacks_160x600', [160, 600], 'div-gpt-ad-1427162132059-0').addService(googletag.pubads());
    googletag.defineSlot('/50217444/Momsnacks_300x250', [300, 250], 'div-gpt-ad-1427162132059-1').addService(googletag.pubads());
    googletag.defineSlot('/50217444/Momsnacks_300x250(mobile)', [300, 250], 'div-gpt-ad-1427162132059-2').addService(googletag.pubads());
    googletag.defineSlot('/50217444/Momsnacks_320x100(mobile)', [320, 100], 'div-gpt-ad-1427162132059-3').addService(googletag.pubads());
    googletag.defineSlot('/50217444/Momsnacks_320x50(mobile)', [320, 50], 'div-gpt-ad-1427162132059-4').addService(googletag.pubads());
    googletag.defineSlot('/50217444/MomSnacks_728x90', [728, 90], 'div-gpt-ad-1427162132059-5').addService(googletag.pubads());
    .setCollapseEmptyDiv(true); //Collapsible div--Collapse this slot before ad fetch
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
    });
    </script>

    Specifically, this code was added: .setCollapseEmptyDiv(true); //Collapsible div--Collapse this slot before ad fetch

    You'll see the ads are not generating, but the space is still parked. The Google contact is basically no help and I have no idea how to get it to collapse when ads do not show. I have it on a test site that is Genesis Magazine theme out of the box.

    http://celebrouhaha.com/

    Any wisdom on this most appreciated.

    http://celebrouhaha.com/
    April 6, 2015 at 10:04 pm #146872
    Brad Dalton
    Participant

    This might be better asked on the Javascipt tag at Stackoverflow.com as i have seen this question before unanswered maybe because its not exactly specific to Genesis or StudioPress. Hope that helps.


    Tutorials for StudioPress Themes.

    April 7, 2015 at 9:19 am #146917
    CJWheels
    Member

    Hey Brad, thanks for the direction. Straight up, I think it's something that falls on the Google end. I can't figure out why they'd hand out mobile code that doesn't take up space on desktops. They keep telling my client it's a developer issue. I disagree.

    My client said, "Ask the smartest people you know." So I came here 😉

    I'll head over there. If I get a fix, I'll post it here as well.

    Cynthia

    April 8, 2015 at 9:31 am #147072
    CJWheels
    Member

    I got this to work thanks to your help! I added the .setCollapseEmptyDiv(true); //Collapsible div–Collapse this slot before ad fetch to each seperate ad I wanted to collapse. Folds down perfectly now.

    <script type='text/javascript'>
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    (function() {
    var gads = document.createElement('script');
    gads.async = true;
    gads.type = 'text/javascript';
    var useSSL = 'https:' == document.location.protocol;
    gads.src = (useSSL ? 'https:' : 'http:') +
    '//www.googletagservices.com/tag/js/gpt.js';
    var node = document.getElementsByTagName('script')[0];
    node.parentNode.insertBefore(gads, node);
    })();
    </script>

    <script type='text/javascript'>
    googletag.cmd.push(function() {
    googletag.defineSlot('/50217444/Momsnacks_160x600', [160, 600], 'div-gpt-ad-1427162132059-0').addService(googletag.pubads());
    googletag.defineSlot('/50217444/Momsnacks_300x250', [300, 250], 'div-gpt-ad-1427162132059-1').addService(googletag.pubads());
    googletag.defineSlot('/50217444/Momsnacks_300x250(mobile)', [300, 250], 'div-gpt-ad-1427162132059-2').addService(googletag.pubads())
    .setCollapseEmptyDiv(true); //Collapsible div–Collapse this slot before ad fetch
    googletag.defineSlot('/50217444/Momsnacks_320x100(mobile)', [320, 100], 'div-gpt-ad-1427162132059-3').addService(googletag.pubads())
    .setCollapseEmptyDiv(true); //Collapsible div–Collapse this slot before ad fetch
    googletag.defineSlot('/50217444/Momsnacks_320x50(mobile)', [320, 50], 'div-gpt-ad-1427162132059-4').addService(googletag.pubads())
    .setCollapseEmptyDiv(true); //Collapsible div–Collapse this slot before ad fetch
    googletag.defineSlot('/50217444/MomSnacks_728x90', [728, 90], 'div-gpt-ad-1427162132059-5').addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
    });
    </script>

    You have to remember to remove the ";" after each ad set when you ad in the collapsible div tag code. That was my mistake.

    April 8, 2015 at 9:37 am #147074
    Brad Dalton
    Participant

    Good stuff!


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble