• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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

Reader Interactions

Comments

  1. Yamasha says

    April 13, 2018 at 9:44 am

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

    Log in to Reply
    • Brad Dalton says

      April 15, 2018 at 4:46 am

      I published these https://wpsites.net/web-design/4-ways-to-execute-code-after-any-number-of-posts-on-paginated-archive-pages/

      Log in to Reply
  2. Yamasha says

    April 12, 2018 at 11:40 pm

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

    Log in to Reply
    • Brad Dalton says

      April 13, 2018 at 3:02 am

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

      Log in to Reply
      • Yamasha says

        April 13, 2018 at 4:18 am

        Something like this?

        if ($recent_posts = wp_get_recent_posts(5))
          return;
        Log in to Reply
        • Brad Dalton says

          April 13, 2018 at 5:22 am

          No, won’t work.

          Log in to Reply
          • Yamasha says

            April 13, 2018 at 6:37 am

            can you help me with fix? )

          • Brad Dalton says

            April 13, 2018 at 6:40 am

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

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags
 

Loading Comments...
 

You must be logged in to post a comment.