• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Adsense add only before pages/posts content not the home page

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adsense add only before pages/posts content not the home page

This topic is: not resolved

Tagged: Adsense add only before content not the home page

  • This topic has 2 replies, 2 voices, and was last updated 8 years, 8 months ago by milada.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • June 11, 2017 at 4:25 am #207595
    milada
    Member

    Hi all,

    I am using Genesis simple hooks. I would like to have my adsense code only before posts and pages not on the home page. So I put the code to the before_content hook.
    The condition for not appearing on a home page, I have this code:

    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    < ?php
    if (is_single())
    {
    echo ' ADSENSE CODE TO DISPLAY ON POST HERE';
    }
    else if
    (is_page())
    {
    echo ' ADSENSE CODE HERE TO DISPLAY ON PAGE';
    }
    ?>

    Where should I paste the PHP code to?
    Thank you in advance!

    Milada

    http://moreyouthfulskin.com
    June 11, 2017 at 4:34 am #207600
    Victor Font
    Moderator

    Adsense code belongs in the spot where you want the ads displayed. You might want to take a look at the Genesis Visual Hook guide to determine placement: https://genesistutorials.com/visual-hook-guide/

    Your condition is more complex than it has to be. And since you are using Genesis Simple Hooks, you might just want to try:

    if ( is_singular() ) {
    ?>
    <script>
    CUT AND PASTE ADSENSE CODE HERE
    </script>
    <?php
    }

    Make sure to check the box for running php code.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    June 11, 2017 at 6:10 am #207608
    milada
    Member

    Thank you for the visual guide.
    I keep the code in before_content Hook and checked the box for PHP code.
    However, when inserting this code:

    if ( is_singular() ) {
    ?>
    <script>
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- MYS Responsive Right Sidebar CS -->
    <ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-3031806710283272" data-ad-slot="1512222341" data-ad-format="auto"></ins>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    </script>
    <?php
    }

    even removed the 2nd </script>
    the ad does not show either on home or posts/pages

    Can you please help?
    Thank you,

    Milada

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble