Your cart is currently empty!
How to Insert or add ad code after every few post in WordPress post loop. Many of users or asking me this question because if you have large number of post in your blog and you want to include add code for Google Adsense code after you post so you can boost your earning.
Like I always say we learn from our our experience same thing I want to do with my blog so I did Research and comes with a code that helps that helps me and hope everyone can use it
First you should know that you must have a little bit PHP knowledge or at least understand that text writing and closing because if you made any changes in core file and that goes wrong the new site might be goes offline or show error that you need to fix from server side be sure take full site backup first or at least theme files.
Also if you are using Google Adsense code then you must familiar with Google Adsense policy as well because using too much ad and low content then your site may harm else you are using any other banner of promo code.
<?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'template-parts/content', get_post_format() ); ?> <?php $postnum++; if($postnum%8 == 0) { ?> YOUR AD CODE <?php } ?> <?php endwhile; ?> <?php the_posts_navigation(); ?> <?php else : ?> <?php get_template_part( 'template-parts/content', 'none' ); ?> <?php endif; ?>
This is main code paste into a post loop and change %8 to any number you want for your ad code to show.
<?php $postnum++; if($postnum%8 == 0) { ?> YOUR AD CODE <?php } ?>
If you have any question regarding this topic let me know in comment section below.
As a consideration use this code in archive pages as well to show your advertisements and Banner in category pages and navigation pages again I strongly recommend you to take backup to be sure.
Comments
5 responses to “Add Ad Code After Every Few Post”
Helpful articles for all users.
helpful article for me
How can i insert 2 or 3 position?
which file i can put this code ?
Good Article & Thankyou
Grabber Pro
Original price was: $59.$39Current price is: $39.Insertcart Custom WooCommerce Checkbox Ultimate
Original price was: $39.$19Current price is: $19.Android App for Your Website
Original price was: $49.$35Current price is: $35.Abnomize Pro
Original price was: $30.$24Current price is: $24.Medical Portfolio Pro
Original price was: $31.$24Current price is: $24.
Latest Posts
- How to Handle Sudden Traffic Spike in Website – Do Node Balancer Really Help
- How to Use AWS SES Email from Localhost or Website: Complete Configuration in PHP
- How to Upload Images and PDFs in Android Apps Using Retrofit
- [Fix] File Permission Issue in Apache Website WordPress Not Writable to 775
- Best PHP ini Settings for WordPress & WooCommerce: Official Recommendations
Leave a Reply