- This topic has 11 replies, 2 voices, and was last updated 7 months ago by
Fernando.
-
AuthorPosts
-
August 22, 2022 at 7:53 pm #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.August 22, 2022 at 8:15 pm #2320712Fernando Customer Support
Hi Pintu,
Are you using a Hook Element?
August 22, 2022 at 8:25 pm #2320724Pintu
Yes
August 22, 2022 at 8:32 pm #2320727Fernando 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 } ?>
August 22, 2022 at 8:37 pm #2320732Pintu
How can I do that with the
hide-on-mobile
class?August 22, 2022 at 8:45 pm #2320737Pintu
<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
andhide-on-tablet
classes to do the job.August 22, 2022 at 8:47 pm #2320738Pintu
Is David here?
August 22, 2022 at 9:05 pm #2320743Fernando 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.
August 22, 2022 at 9:08 pm #2320746Pintu
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 } ?>
August 22, 2022 at 9:16 pm #2320748Fernando Customer Support
Yes. Make sure to enable Execute PHP.
August 22, 2022 at 9:18 pm #2320750Pintu
Thanks, Fernando for your help. It worked 🙂
August 22, 2022 at 9:25 pm #2320755Fernando Customer Support
You’re welcome Pintu! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.