Insert an advertising block between two articles WordPress

pub_haut
As you know, include an advertising block on the home page in a WordPress theme is not easy when you know nothing about PHP. With this method and this code, you will be able to integrate in a few clicks an advertising block in the loop of the home page of WordPress.

Tutorial source in French:

Example of final rendering of an advertisement inserted between two articles: (click to enlarge)

How to do ?

Go to your WordPress administration then Appearance / editor / index.php (or directly to your FTP …). Make a backup of your index.php before if you want.
Locate the following line:

<?php while (have_posts()) : the_post(); ?>

Once you have found this line you must enclose the command with the following PHP code:

<?php $counter = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $counter ++;?>

Then copy the following code where you want with the content of your choice. You can change the number (4 here) with the one you want to change the location of the display between articles.

<?php if((4== $counter) ): ?>
Content
<?php endif; ?>

Replace « content » to put what you want, adsense code, a div, or whatever your imagination dictates you…


You might also like:

Leave a Reply

This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage.

Top