Display advt after specific post on Blog Page in Astra theme

Do you want to display advertisement after a specific number of posts on the blog page? This can be achieved in the Astra theme using custom code. Besides executing ad code, you can use the same code logic to display any content between posts listing on the blog page.

Display ads between posts on Blog Page

In the WordPress Dashboard, go to Appearance > Theme Editor and open the functions.php file of your Astra chid theme. Then add the following code at the end. Alternatively, you can use code snippets plugin for adding custom code.

The above code will execute and display advertisement after the 3rd and 7th post. You can change 3 and 7 in the code for specific ad location as per requirement. Also, replace “Enter your Ads script here” with the actual advertisement code or contents that you want to display.

For posts on Archive & Category Pages

In addition to the blog page, if you want to display advertisements between posts on the archive and category pages, then use the following code.

In the above code, there are two new conditional logic is_archive() & is_category() into the IF statement for executing this on archive and category pages.

Share this Tutorial

Leave a Comment