[Resolved] Hide AdSense ads on Mobile device

Home Forums Support [Resolved] Hide AdSense ads on Mobile device

Home Forums Support Hide AdSense ads on Mobile device

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2320699
    Pintu

    Hi, I’ve added 970 x 90 AdSense Ads in GeneratePress after header using Hook > after_header. Though the ad shows fine on desktop, and I’ve no problem with it.
    But I don’t want to show the ad on a Mobile device, because it is a fixed Ad and doesn’t show that great on mobile. Therefore, how can I hide this particular ad on a mobile device?
    I’ve added my site link in the private section, please help. Thanks in advance.

    #2320712
    Fernando
    Customer Support

    Hi Pintu,

    Are you using a Hook Element?

    #2320724
    Pintu

    Yes

    #2320727
    Fernando
    Customer Support

    You could try enclosing the ad code in a php conditional statement. Example:

    <?php 
    if( ! wp_is_mobile() ) { ?>
    
    <!-- add ad code here -->
    
    <?php } ?>
    #2320732
    Pintu

    How can I do that with the hide-on-mobile class?

    #2320737
    Pintu
    <div align="center">
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-74341"
         crossorigin="anonymous"></script>
    <!-- After Header Ads -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:970px;height:90px"
         data-ad-client="ca-pub-74341"
         data-ad-slot="4230300"></ins>
    <script>
         (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    </div>

    This is the ad code I’ve added, and I wanted to know if can I use the GP hide-on-mobile and hide-on-tablet classes to do the job.

    #2320738
    Pintu

    Is David here?

    #2320743
    Fernando
    Customer Support

    David’s out of shift right now.

    Using hide-on-* for ads is not allowed by Google unless it’s a responsive ad unit.

    Are you using a responsive ad unit? If so, here’s how to do it: https://support.google.com/adsense/answer/9183363?visit_id=637968240625154645-2866526188&rd=1#hide&zippy=%2Chiding-ads-for-specific-screen-sizes-example:~:text=screen%20width%20example-,Hiding%20an%20ad%20unit,-In%20certain%20cases

    Otherwise, only adding the script through a PHP conditional statement should work as well.

    #2320746
    Pintu

    Okay, so the new code should be like the following?

    <?php 
    if( ! wp_is_mobile() ) { ?>
    
    <div align="center">
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-74341"
         crossorigin="anonymous"></script>
    <!-- After Header Ads -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:970px;height:90px"
         data-ad-client="ca-pub-74341"
         data-ad-slot="4230300"></ins>
    <script>
         (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    </div>
    
    <?php } ?>
    #2320748
    Fernando
    Customer Support

    Yes. Make sure to enable Execute PHP.

    #2320750
    Pintu

    Thanks, Fernando for your help. It worked 🙂

    #2320755
    Fernando
    Customer Support

    You’re welcome Pintu! 🙂

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.