Monetization

How to Install Mobile Ads on WordPress Sites

Sovrn Publisher Advocate // March 14, 2016

iphone
Ever wondered how to install mobile ads on WordPress? Look no further. Here’s how to start making money from mobile advertising on your WordPress site.

How to Install Mobile Ad Code Using a Plugin

1. Login to your WordPress dashboard and click “Plugins”.

2. Search “Insert Post Ads Plugin” and download.

3. Click on Post Adverts » Add New. On the next screen, name the ad, paste in the mobile code, and select the paragraph you want to display the ad code after. Once done, click publish.
4.) Next go to Post Adverts » Settings to select which post types you want to show the ads on (ex. posts, pages, and custom post types).

Note: This plugin is not specifically for a WordPress mobile site (with a Mobile theme). If you have a specific mobile theme for their site, they can use a WP plugin like Jetpack to insert ads. This plugin has a pretty straightforward interface for mobile theme, and all you do is put the mobile ad code in the ‘Custom Ads’ section.

 

How to Install Mobile Ad Code Without a Plugin

If you want to install mobile ad code without a plugin, you can hardcode the mobile tag into your site directly.

1. Open your theme’s functions.php or a site-specific plugin file and paste the in following code:

01 <?php
02
03 //Insert ads after second paragraph of single post content.
04
05 add_filter( 'the_content''prefix_insert_post_ads' );
06
07 function prefix_insert_post_ads( $content ) {
08
09 $ad_code '<div>Ads code goes here</div>';
10
11 if ( is_single() && ! is_admin() ) {
12 return prefix_insert_after_paragraph( $ad_code, 2,$content );
13 }
14
15 return $content;
16 }
17
18 // Parent Function that makes the magic happen
19
20 function prefix_insert_after_paragraph( $insertion,$paragraph_id$content ) {
21 $closing_p '</p>';
22 $paragraphs explode$closing_p$content );
23 foreach ($paragraphs as $index => $paragraph) {
2. To add the ad code, edit $ad_code value where it says “Ad code goes here” on line 9.  To change the paragraph number, just change the number 2 to another paragraph number on line 12.

 

If you have any additional questions on how to install mobile code in WordPress, ask us in the comments or drop us a line at support@sovrn.com.

Want to learn more?

Share this article