Skip to content

Instantly share code, notes, and snippets.

@AbhishekGhosh
Created October 15, 2016 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhishekGhosh/562fe8764efe7d96645e75d410fbe20d to your computer and use it in GitHub Desktop.
Save AbhishekGhosh/562fe8764efe7d96645e75d410fbe20d to your computer and use it in GitHub Desktop.
AdSense WordPress PHP wp_is_mobile
<?php
if ( wp_is_mobile() ) {
echo '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- your_unit_name -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-xxxxxxxxx"
data-ad-slot="xxxxxxxxx"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
}else if ( !wp_is_mobile() ) {
echo '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- your_unit_name -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-xxxxxxxxx"
data-ad-slot="xxxxxxxxx"
data-ad-format="rectangle"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment