As you know AMP for WordPress only let you put Ads at the header, footer, above content, below content, etc…
…but it has not a single option to put ads in the middle of content.
So If you want to insert Ads after few Paragraphs, Headings, Div, etc when you are using AMP for WP – Accelerated Mobile Pages plugin:
You just need to follow this guide.
Note: This is the simple guide for everyone and even for the person who not know about WordPress theme or plugin development.
AMP Insert Ad in Post Content (Version 0.9.85.2)
First: Let me tell you when you use AMP for WP, you do choose design theme. It may be Design One, Design Two or Design Three.
So no matter which theme you have selected, the function code that I am going to give you will work on all.
Just remember the design theme name that you have selected.
Go to the AMP for WordPress plugin folder by using Cpanel, FileZilla, or any FTP transfer software…
…Now open content.php file from Design Folder (design-1, design-2, design-3) which you have selected that located at: wp-content > plugins > accelerated-mobile-pages > templates > design-manager > design-3 (We chooses Design Three) > elements > content.php
The content.php file will have the codes like below:
You just need to replace from
echo $ampforwp_the_content; to the following codes in the line No: 31
$p_number value to the number of paragraph after you want to display ad.
And after that:
ca-pub-XXXXXXXXXXXXXXXXXXXto your’s publisher id and
data-slot-id as per your Google Adsense ads id too.
Download Final Code
Multiple Ads After Number of Paragraph
For displaying multiple ads after certain number of paragraph, you need to just copy the above code from Line No: 13-16.
And paste it after Line No: 16 as much as you want.
Example: I want to display 3 Ads, which will be shown after 4, 12, and 23rd Paragraph tag.
Note: Don’t forget to change data-slot-id (Ads ID).
Demo of AMP Ads between post content: Old Songs
Hope you successfully added Google Adsense Ads in the Content when you are using AMP for WP.
Good News: We will keep up-to-date this codes whenever new Updates come for AMP for WP. If we forget, Just let us know via comment or email.
Don’t forget to share this AMP Insert Adsense ads in the middle of content without plugin.