• Resolved anonymized-12966443

    (@anonymized-12966443)


    I have to insert"<script data-ad-client="ca-pub-0000000000000000" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>"in the HEADER section of Ad Inserter.

    This is needed for inserting the vignette ad.

    The problem is, I don’t know how to disable the header code for signed in users.

    How to disable auto ads in the Header section for members?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter anonymized-12966443

    (@anonymized-12966443)

    I think I have it but I’m not sure.

    1. Add code to block: |
    <script data-ad-client=”ca-pub-00000000000000″ async src=”https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js”></script&gt;
    2. Insertion before post
    3. taxonomy, I select the user roles the block needs to be disabled for.
    4. place the shortcode [adinserter block=”1″ check=”exceptions”] this in the header.

    I tested it and I believe it works. Let me know if this is right?

    Plugin Author Spacetime

    (@spacetime)

    It should be easier to select Not-logged in users:
    https://adinserter.pro/documentation/additional-block-settings#insertion

    No need to check for exceptions in the shortcode.

    Thread Starter anonymized-12966443

    (@anonymized-12966443)

    The problem with your solution is, when someone sign up and not pick a subscription the ads will be disabled while not paying a small fee to support my work. So I have to manual pick the user roles.

    Why do you advice not to check the exceptions?

    • This reply was modified 3 years, 10 months ago by anonymized-12966443.
    Plugin Author Spacetime

    (@spacetime)

    If you are actually using individual post or page exceptions for thsi block then use it.
    Of course, you can use any user role.

    Another solution for disable google auto ads for logged in user:

    1. Goto wp settings > Ad Inserter
    2. Click on the last tab (gear icon)
    3. Click on the tab Header
    4. Click on the PHP button above code window to enable php code (purple light must be on)
    5. paste this php code into the code window <?php if ( ! is_user_logged_in() ) echo '<script data-ad-client="ca-pub-0000000000000000" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>' ?>
    6. Replace ca-pub-0000000000000000 with your Publisher ID
    7. Click on the Enable button above code window to enable header code (green light must be on)
    8. Click on the Save Settings button to save settings
    • This reply was modified 3 years, 6 months ago by sekedus.
    • This reply was modified 3 years, 6 months ago by sekedus.
    Thread Starter anonymized-12966443

    (@anonymized-12966443)

    Much appreciated @sekedus

    Thread Starter anonymized-12966443

    (@anonymized-12966443)

    @sekedus oh one problem with your solution I pointed out in my previous answer. I use custom roles.

    Thread Starter anonymized-12966443

    (@anonymized-12966443)

    @sekedus / @spacetime my code is this:

    <?php
    $user = wp_get_current_user();
    $allowed_roles = array('subscriber', 'visitor');
     if ( array_intersect($allowed_roles, $user->roles ) ) echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXX" crossorigin="anonymous"></script>' ?>

    I only want the adsense code appear in the HEAD section for site visitors and users with a subscriber role. However ‘visitor’ does not exist and I fail to find a proper solution for this.

    Looking forward for your reply.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How-to disable Auto Ads Code in Header for Logged-in users?’ is closed to new replies.