Created
March 28, 2023 10:57
-
-
Save seemly/37a284d220aa5513e2b5e6ee5e72a835 to your computer and use it in GitHub Desktop.
Conditionally hide Google Adsense snippet on a WordPress site using WP Code and ACF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Check if ACF function `get_field()` exists. If it doesn't exist, display ads won't be shown. | |
// If it does exist and ACF 'hide_display_ads' value is not falsey, show display ads. | |
if(function_exists('get_field') && !get_field('hide_display_ads')) | |
{ | |
echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-[your-adsense-id]" crossorigin="anonymous"></script>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment