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

Nile Flores Media

Helping You Rock Out Your Website Like A Rockstar

  • Home
  • About
  • Blog
  • Portfolio
  • Hire Me
  • Resources
  • Contact
  • Blogging
  • WordPress
  • Social Media
  • SEO
  • Web Design
  • News
  • Podcast
You are here: Home » WordPress » Adding Content Between Posts In Genesis

Adding Content Between Posts In Genesis

By Nile Flores 15 Comments


genesis-theme-tutorials-thumbnailI’ve written a short tutorial in the past about being able to add Adsense or any other content between posts in WordPress. The Genesis theme framework by StudioPress is a bit different. The concept is not all that different, but applying the method requires knowing a little PHP and the hooks to the Genesis theme framework.

Before getting into the code, I want to make a big shout out to Phil McDonnell for helping me wrap my head around this code. The following resources were available, but none worked as Genesis 2.0 changed a bit since implementing HTML 5.

  • Desired content between Loop
  • Conditional Loop Actions

Adding Content Between Posts In Genesis

Essentially in a list of posts, we will have several loops. We want our code to be between the posts, but not cut out of the loop where it may not display properly. With the HTML5 markup that is in Genesis, we don’t want to use the hook genesis_after_post for, but the HTML5 hook for genesis_after_entry. Check out the Genesis Visual Markup Guide to see where it will fit.

We also want to put a loop counter in place so the code will automatically print after so many posts. Lastly, we need to tell this code how many posts should display before the content or advertisement will be shown.

<pre class="lang:default decode:true " >// Put text into the loop but only after every third post
add_action( 'genesis_after_entry', 'themeprefix_between_post_content' );

function themeprefix_between_post_content() {
global $loop_counter;

$loop_counter++;

if( $loop_counter == 3 ) {

echo 'This will print every third post!';

$loop_counter = 0;

}

}</pre> 

Don’t forget to change the themeprefix in the above code to whatever text domain you have specified for your theme.

Please note, this is a counter after so many number of posts, and not on specific posts… like after post 2 and post 7. It is an equal amount of posts. Also, if you’re using this to display Adsense, please make sure you’re up-to-date on how many display spots are allowed on a single page. If you use more than what the rules permit, then you may end up suspended from Adsense. (Note: As for December 2013, the max amount of Adsens slots that can be displayed per page is 3.)

You can also replace the printed area (the line with the term ‘echo’) with a widget so you can edit that area anytime with whatever content you want.

Adding Content Between Posts In Genesis – Adding A Widget

1. You need to register a new widget in your theme’s functions.php file

//* Register Between Post Content Widget 

genesis_register_sidebar( array(
'id' => 'between-post-content',
'name' => __( 'Between Post Content', 'theme-prefix' ),
'description' => __( 'This is the widget between every few posts.', 'theme-prefix' ),
) );

2. Use the code above and add the widget to it. We want the widget content to only appear if content has been dragged into the widget via Appearance> Widgets.

//* Add widget to after entry to output every 3 posts
add_action( 'genesis_after_entry', 'themeprefix_between_post_content' );

function themeprefix_between_post_content() {
global $loop_counter;

$loop_counter++;

if( $loop_counter == 3 ) {


if ( is_active_sidebar( 'between-post-content' ) ) {
    echo '<div class="between-post-content widget-area"><div class="wrap">';
	dynamic_sidebar( 'between-post-content' );
	echo '</div></div><!-- end .top -->';
	}

$loop_counter = 0;

}

}

We want to use the class for wrap as that is what most of the sidebars in Genesis 2.0 are using since implementing HTML5.

3. Add style to your themes style sheet for the .between-post-content.

Pretty cool trick, huh? 🙂


Filed Under: WordPress Tagged With: ads between posts, ads between posts in genesis, content between posts, genesis tutorial

About Nile Flores

Nile is a 43-year old female from the greater St. Louis (Southern Illinois side) area. Nile is a mother of 1 son. She is also a web designer and developer, a graphic designer, and a public speaker, who exclusively designs and develops using WordPress. She also blogs at GoDaddy's Blog, Verpex Hosting's blog and her very personal sites, Pixelled and Nail Polish Happy.




Related posts:

No related posts.

Reader Interactions

Comments

  1. Shiv Saroya says

    December 2, 2013 at 6:13 am

    Yes, I realized that was the better way of doing it. So I modified the post. Glad to help.

    Reply
  2. Gautam says

    December 3, 2013 at 10:38 pm

    Great tutorial,one can add adsense Ads between posts and add any type of widget too.This tutorial will really help genesis users including me.

    Reply
    • George says

      December 4, 2013 at 9:07 am

      For adding adsense ads you can use plugin named ad injection. I dont its possible to add widget in between posts.

      Reply
  3. Jenny says

    December 4, 2013 at 8:32 am

    hmm this looks handy. gonna have to save this for when i figure out my new theme… IF i ever do :\

    Reply
  4. Zimbrul says

    December 4, 2013 at 4:43 pm

    What I like in Genesis is that you can add “bits” pretty much anywhere and if you are a master of CSS you end up with pretty cool effects.

    Reply
  5. Vinay says

    December 5, 2013 at 11:16 am

    Great post..Iam looking for this info for a long time and thanks for the article

    Reply
  6. Dr. Erica Goodstone says

    January 4, 2014 at 9:48 pm

    Nile,
    Very interesting. Does this type of code work with other themes?
    Since I have never used the php, I would not know how to get in there to add the code.
    But it is really cool to be able to have your ad pop up, I am assuming it shows at the bottom or on the sidebar at the scheduled interval between posts. Or does it appear as a popup?

    Warmly,

    Dr. Erica

    Reply
  7. Rebekah Radice says

    January 6, 2014 at 6:37 pm

    Thank you, thank, you, thank you for this Nile! I have been trying to find an answer to this exact question. I, like you, just couldn’t wrap my head around it.

    You always seem to have just the answer I need!

    Reply
  8. Pankaj says

    January 11, 2014 at 8:10 am

    I am using Genesis on few of my blogs. And this tutorial is really helpful for me. I will use these steps.

    Reply
  9. Nick G says

    February 8, 2014 at 11:12 am

    Hello, the code works beautifully, but for some reason on my mobile site it shows the widget between every single post on front page as opposed to just the very first post. Do i need to modify the code in some way to accommodate this?

    Reply
    • Nile says

      February 14, 2014 at 3:49 am

      It shouldn’t do that… because it works with the loop count unless you left the number at 1… then it will. I suggest if you do display 10 posts to a page, then you think about making the number every 3 posts or so. In mobile, you need to add in the style.css under media query that the area is hidden.

      Reply
    • Big F says

      May 18, 2014 at 1:43 pm

      I have taken similar code from several sites to modify the genesis loop counter and tried to apply default loop on my site. They all output the widget after each post however and seem to ignore the loop counter. Did you solve this and can you give me a hint Nick? Pretty frustrating stuff.

      Reply
  10. Danny says

    March 13, 2014 at 11:54 pm

    Hello! Great tutorial.
    I can apply in the Child Theme Genesis ? I’m using Focus Pro Child.

    Reply
    • Nile says

      May 25, 2014 at 3:09 am

      Yes, you definitely can apply this to that.

      Reply
  11. Saurab Parakh says

    March 14, 2014 at 12:06 pm

    In my opinion stuff like ads between posts irritates the article reader because it is a kind of irrelevant stuff in between. Btw while I started my blog a couple of years back, I too was very exited about putting the ads in between.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Follow Me On:

  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube

Get The Latest WordPress & Blogging Tips

Sign up for my newsletter, and also get my free ebook on 10 Reasons Why Your Website Isn't Converting, and How to Fix it!




Try to be More Positive on Social Media

Note: You can click on image and view the video in a larger lightbox window.

Footer

The Blog

Lots of free information, tutorials, and more to help you bring your best foot forward with your website.

  • Blogging
  • WordPress
  • Social Media
  • SEO
  • Web Design

Get The Latest WordPress & Blogging Tips

Sign up for my newsletter, and also get my free ebook on 10 Reasons Why Your Website Isn't Converting, and How to Fix it!

Copyright © 2025 · · WordPress