At Crunchify we are using Genesis Framework since last 5 years. Without a doubt it’s one of the most popular WordPress Theme Framework out there.
As you may have noticed recently, last week we have upgraded theme at Crunchify.com and wanted to have nice 728x90 ads
in middle of posts on home page.
- How can I insert ads on the homepage?
- How to insert Ads between posts in your WordPress homepage site?
- Where to paste the ad code in your HTML?
On Crunchify, we have decided to show top 9 posts on home page. If you want to make any changes on how many posts you want to show then go to Settings
-> Reading Panel
and make changes.
If you have any of below questions then you are at right place:
- How to insert Ads between posts in your WordPress homepage site
- Embed Ads In The Middle of WordPress Loop
- How to insert an ad between posts in WordPress
- WordPress HomePage Loop and Adsense
As we have total 9 posts on home page, we want to have 728x90 ad
appears after 2nd and 5th post. In order to achieve that just add below code to your theme’s functions.php file.
add_action( 'genesis_after_entry', 'crunchify_ad_on_home' ); function crunchify_ad_on_home() { global $loop_counter; $loop_counter++; if( (!is_paged() && !is_singular()) && ($loop_counter == 1 || $loop_counter == 4)) { echo '<div style="margin-bottom:25px;"><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-4032710958875645" data-ad-slot="7425196307"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>'; $loop_counter = $loop_counter + 1; } global $loop_counter_paged; $loop_counter_paged++; if( (is_paged() ) && ($loop_counter == 2 || $loop_counter == 5) ) { echo '<div style="margin-bottom:25px;"><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-4032710958875645" data-ad-slot="7425196307"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>'; $loop_counter_paged = $loop_counter_paged + 1; } }
As you see in above code we have Grid layout on Crunchify hence we have different requirement to show ads after 1st and 4th post.
Code is pretty simple. It will add ads after specific loop counter. Just change loop_counter
value as per your need. Please change your adsense ID and replace with your ad code.
You could see it live on Crunchify home page
. Let me know if you face any issue implementing this.
Interested to see new UX for Google Adsense Ads?
While creating new Adsense Ads I just noticed new UI for creating Ads.
What do you think about new process of creating Adsense ads?