Select Page

In previous post I described how to Display Adsense banner on the left sidebar in posts in Divi theme. In this article we put Adsense banner before all posts using Divi theme. Here is supposed that you using a child theme on your site.

Create a sidebar for your Adsense code

First we will create a sidebar where your Adsense code will reside. For this purpose go to Dashboard – Appearance – Editor. Find functions.php for your child theme and add next code to it:

You can use alternative way to add a new sidebar using Divi’s feature in Appearance – Widgets:
divi widgets sidebar above post
But adding sidebar in code is more customizable.

Add a ET Adsense widget to the new sidebar

Open Dashboard – Appearance – Widgets. Here you can see the new Adsense Above Post sidebar. Move ET Adsense Widget from the left side to this sidebar. Add your Adsense code into added widget.
ET Adsense widget

Insert sidebar above all posts

To modify all posts you need to edit single.php. I hope you already have this file in you child theme’s folder. If not then copy it from Divi folder. Open for edit and find an appropriate place for Adsense sidebar. Add next php code:

For example, you can insert it just before content. In my version of single.php at Line 90: