RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.38% (6.14%*) • Home Loan Fixed: 5.44% (6.26%*) • Fixed: 5.44% (6.26%*) • Variable: 5.38% (6.14%*) • Investment IO: 5.69% (6.52%*) • Investment PI: 5.49% (5.98%*)

Simple AdSense WordPress Plugin

Simple AdSense WordPress Plugin

After having a quick look at the plethora of AdSense plugins hosted on WordPress, we were a little blown away by the complexity offered by many of them (particularly those with high rankings). While many were feature rich and excellent plugins, they usually offered far more than was normally required for your average blogger starting out with WP and the inevitable AdSense integration. To address this, we turned an (old) shortcode function into a more robust plugin that'd support what we consider to be the core features... and designed it to be simple to use. While we've included a shortcode snippet, we'd recommend downloading the plugin for ease of use, updates, and additional features.

Plugin Features

The plugin currently supports the most basic of features:

  • Up to 10 ad units (we'll increase this to unlimited in the next version).
  • Conditionally prevent AdSense from displaying on specific posts or pages (from your publish meta box).
  • Display both desktop and mobile ads, with optional adverts for when you switch off AdSense.
  • Exclude AdSense from displaying to users with a specific IP address (displays alternate adverts instead).

Plugin Usage

Download the plugin and activate via your WordPress dashboard. The first thing you'll need to do once activated is navigate to Tools -> BeliefMedia AdSense and create some ad blocks. Select a block via the Select AdSense Code Block dropdown.

Simple AdSense WordPress Plugin

There are two sections: desktop ads and mobile ads - the latter adverts will render on mobile devices. The alternate adverts display when you've chosen to disable ads for a particular post or page, or when you've black-listed your IP address. To upload an image, click the upload button and either upload or select an image, or just enter a URL. There are a number of changes we'd like to add here but it'll have to wait for another version. At the moment it does what it needs to do on the site it was built for.

Disable AdSense Displaying on a Post or Page

There are times when you will want to disable ads from displaying on a particular page - most notably when your page violates Google's AdSense policy. The option to disable page-level ads is included in your publish meta box.

Simple AdSense WordPress Plugin

Blacklist IP Addresses

To avoid unwanted or accidental clicks, you can list any number of IP addresses that will essentially be blacklisted. When page requests are made via these IPs, the alternate adverts will be shown. Every time you log into the control panel from a new IP address, you will be notified. The IP will automatically be added to your exclusion box (you'll still need to save it for the IP address to be saved).

Simple AdSense WordPress Plugin

There's an option to show or hide the ads to your exclusion list.

Usage

When you create an advert option you'll be presented with the ad block ID. Simply use [adsense type="1"] for the block you would like to render.

Simple Shortcode Alternative

If you're after a simple shortcode and don't want the plugin-based features, consider the following code. Populate each $adsense_code variable in the switch statement and call it as [adsense type="x"] - where x is the code block. To wrap the block in paragraph tags, use p="1". A single alternative exists for a mobile advert; the expectation is that a single width advert or responsive ad type will be used.

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 BeliefMedia AdSense Shortcode
4
 http://www.beliefmedia.com/adsense
5
*/
6
 
7
function beliefmedia_display_adsense($atts) {
8
 
9
  $atts = shortcode_atts(array(
10
    'type' => '1',
11
    'style' => 'text-align:center;',
12
    'p' => 0
13
  ), $atts);
14
 
15
  switch ($atts['type']) {
16
    case '1':
17
        $adsense_code = '';
18
        break;
19
    case '2':
20
        $adsense_code = '';
21
        break;
22
    case '3':
23
        $adsense_code = '';
24
        break;
25
    case '4':
26
        $adsense_code = '';
27
        break;
28
    case '5':
29
        $adsense_code = '';
30
        break;
31
    case '6':
32
        $adsense_code = '';
33
        break;
34
    case '7':
35
        $adsense_code = '';
36
        break;
37
    case '8':
38
        $adsense_code = '';
39
        break;
40
    case '9':
41
        $adsense_code = '';
42
        break;
43
    case '10':
44
        $adsense_code = '';
45
        break;
46
    default:
47
        $adsense_code = '';
48
        break;
49
  }
50
 
51
 /* Mobile alternative */
52
 $mobile_adsense = '';
53
 
54
 /* Return code */
55
 $return = (wp_is_mobile() !== false) ? '<div style="' . $atts['style'] . '">' . $mobile_adsense . '</div>' : '<div style="' . $atts['style'] . '">' . $adsense_code . '</div>';
56
 if ($atts['p']) $return = '' . $return . '';
57
 return $return;
58
}
59
add_shortcode('adsense', 'beliefmedia_display_adsense');

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Considerations

  • When you create an AdSense ad on Google's website you will be presented with an option for alternate adverts to render. The alternative advert you select at the AdSense level should normally be the same as the alternative advert you upload via the plugin.
  • The primary ad you select doesn't have to be a Google AdSense advert; it can be anything.
  • Various text an option formats (and other placeholder images) can be found here.
  • Simple and basic AdSense snippet here.

Download

Updated download is pending.

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment