• 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

Add Adsense Code to Homepage and Category pages after 1st Post

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 › Add Adsense Code to Homepage and Category pages after 1st Post

This topic is: not resolved

Tagged: ads, adsense, advertisement, post count, widgets

  • This topic has 5 replies, 3 voices, and was last updated 10 years, 9 months ago by jhuotari.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • August 5, 2014 at 8:54 pm #117243
    jponline
    Member

    Hi,

    I use the Streamline 2.0.1 Child Theme with Genesis 2.1. I'm trying to add an Adsense banner ad after the 1st post excerpt (just above the picture of the 2nd post) on the Homepage and in all the category pages.

    I've searched and tried several things.

    I added the following code to the Genesis Simple Hooks Plugin in the genesis_before_loop Hook:

    <?php
    if( is_category() || is_home() )
    { ?>
    GOOGLE ADSENSE CODE
    <?php
    }
    ?>

    That works well but it only adds in before the 1st post.

    I tried to register widgets in functions.php and all the codes suggested in the detailed post by Brad Dalton here:

    Add Content After Any Number of Post Excerpts In Any Type Of Archive

    Only the last option works but it shows the add after the 1st title ... and not after the excerpt.

    I tried to add the following suggested code but nothing shows up:

    add_action( 'genesis_after_entry', 'google_ad' );
    function google_ad() {
    
    	if ( ! ( is_home() || is_category() ) )
    		return;
    
    	global $wp_query;
    	if(($wp_query->current_post == 0) || ($wp_query->current_post == 1)) {
    		echo '<div class="adsense">Adsense code here</div>';
    	}
    
    }

    Does anybody have any clue how to achieve it with Streamline?

    Thanks a lot

    August 5, 2014 at 9:54 pm #117258
    Brad Dalton
    Participant

    Is your version of Streamline running HTML 5 or XHTML markup?

    The PHP code i included uses HTML 5 loop hooks so it won't work on old themes running XHTML markup with the old loop hooks.

    All code in the post you linked to is tested and works

    The different code snippets provide different solutions based on different conditions so may not solve the exact problem you have.

    Link to your site please


    Tutorials for StudioPress Themes.

    August 5, 2014 at 10:37 pm #117266
    Brad Dalton
    Participant

    Here's the screen shot testing the first code snippet in the post you linked to on my site which creates a widget that outputs after the first excerpt.

    I tried to add the following suggested code but nothing shows up:

    The screen shot also shows the text which it output using another code snippet from the same post you linked to and the code from my site you embedded above.

    The banner add you see on the screenshot was added to the widget the code generates and displays after the excerpt on the first post in the archive only which is what you want so why do you state it doesn't work?

    Blog

    Both solutions display content after the excerpt however the code you posted adds it after all excerpts and the code for the widget only after the first post.

    Please understand a few things:

    The Streamline Pro theme does not include a loop on the front page ( in the home.php file ) so the posts page in this case is the blog page according to your reading settings and the blog page template your use.

    You can change this simply my changing the conditional tags which will also enable you to output your add after excerpts on the category archive pages.

    The home page and the front page are not the same nor are the conditional tags


    Tutorials for StudioPress Themes.

    August 6, 2014 at 10:55 am #117374
    jponline
    Member

    Hi Brad,

    Thanks for taking the time to answer me. After reading your messages, I updated the Streamline Child Theme from 2.0.1 to 3.0.1 and it did the trick. You were right, it probably wasn't built on HTML5 and that's why it didn't work.

    Anyway, now it's perfect and I like how simple you made it on your site and how easy it was to add the widget.

    Have a good day and thanks again!

    August 6, 2014 at 7:40 pm #117483
    Brad Dalton
    Participant

    Glad to hear it!


    Tutorials for StudioPress Themes.

    September 11, 2014 at 11:46 pm #124071
    jhuotari
    Member

    Thank you both very much.

    Brad, for several months, I've been wanting to insert ad widgets between post excerpts on category archive pages. But I wasn't sure how to insert a different widget after different post excerpts, for example, widget #1 and #2 after post excerpt #1, widget #3 and #4 after excerpt #2, etc. I knew I needed to use a post count somehow, but I wasn't sure how to do that. Now, I have a place to start, thanks to your code. Thank you!

    The main reason I want to do this is to get the ads higher in the content flow when our website is viewed on a mobile device, especially a smartphone. Right now, too many of our ads are in the sidebar, which drops below the main content area on a mobile device. And I'm concerned that too many mobile readers might not be seeing those ads, so I'm trying to improve their prominence and effectiveness.

    John Huotari
    OakRidgeToday.com (We're using a modified version of the News Pro theme.)

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 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

© 2025 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