Code to Disable AdSense Ads for Logged In Users in WordPress

/* Disable Google AdSense Ads for Logged In Users */ 
add_action('wp_head', 'wpflt_adsense_script_logged_out_users');
function wpflt_adsense_script_logged_out_users() {
 if ( !is_user_logged_in() ) { ?>		
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxxxxxxxx"
     crossorigin="anonymous"></script>
  <?php
 }}

Add this snippet to your child theme’s functions.php to disable Google AdSense script for logged in users. We as admins spend a lot of time on our sites creating content. Having ads while working on websites for customizing themes creates annoyance. So with this code, Ads will be disabled for Admins and Editors. Make sure you update your Adsense ID in Line 5.

Technically, with this code added, AdSense Script runs only for users who are logged out, meaning, it runs only for our visitors.