Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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