WP SITES

3086 Coded Tutorials & 291 Plugins

Conditionally Remove Adsense Auto Ads From Posts in Specific Category in Genesis

Genesis includes a input field for Adsense auto ads located in Genesis > Theme Settings > Google Adsense. However, this settings outputs the script on every age of your site.

If you want to control where the script loads, you can add the script manually using the following PHP code in the end of your child themes functions file. Swap out the google_ad_client value with your Google AdSense Publisher ID ca-pub-xxxxxxxxxxxxx in the code.

Note : Both code snippets in this tutorial remove adsense from posts in the category “sponsored”.

Do not use the Genesis > Theme Settings > Google Adsense settings if using the code above.

Genesis [adsense_hint] shortcode

You can also hook in the shortcode using conditional tags and genesis hooks in your child themes functions file.

This code outputs this HTML in the source code :

<div><ins id="ad-135-1" style="display: none;" class="adsbygoogle-placeholder"></ins></div>

Learn more about Adsense Auto Ads in Genesis

8 responses to “Conditionally Remove Adsense Auto Ads From Posts in Specific Category in Genesis”

  1. Yamasha Avatar

    i understand. i found a solutions. thank you. 🙂

  2. Yamasha Avatar

    Can I disable the ads only for last 5 articles on my blog, not for category?

    1. Brad Dalton Avatar
      Brad Dalton

      Yes you can however you’ll need to code a custom conditional tag to check for the latest 5 posts.

      1. Yamasha Avatar

        Something like this?
        [code]
        if ($recent_posts = wp_get_recent_posts(5))
        return;
        [/code]

        1. Brad Dalton Avatar
          Brad Dalton

          No, won’t work.

          1. Yamasha Avatar

            can you help me with fix? )

          2. Brad Dalton Avatar
            Brad Dalton

            Sure, Please sign up here https://wpsites.net/register/

Leave a Reply

New Plugins