Friday, June 29, 2012

WordPress Plugin for Simple Google Adsense Insertion/Integration

Easy to use WordPress plugin to insert Google Adsense to your posts, pages and sidebar by using a trigger text or calling the php function.

There are many plugins and services which can add Google Adsense to your WordPress site. However I found that even though something like Adsense Manager or Adsense Deluxe provides a lot of customizable options, it can be overwhelming and isn’t really simple enough for people who are new to WordPress or for people who simply want to insert Google Adsense to their site in a few clicks.
I found that most of the time I only use two or three types of Google Adsense units in various places and posts throughout my sites. Google’s Adsense policy mentions to not have more than three adsense block in one page anyway. That’s why I wrote my own Simple Adsense Insertion Plugin for WordPress, to focus on having 1-3 Google Adsense codes saved and use them where ever I want on my site by inserting a simple trigger text to my posts,pages and sidebar.

Installation

1. Unzip and Upload the folder ‘WP-Simple-Adsense-Insertion’ to the ‘/wp-content/plugins/’ directory.
2. Activate the plugin through the ‘Plugins’ menu in WordPress.
3. Go to Settings and configure the options eg. Copy and paste the Google Adsense code that you want to use.
4. Add the trigger text [wp_ad_camp_1] to a post or page where u want it to appear.

Usage

There are two ways you can use this plugin:
1. Add one of the following shortcodes (trigger text) on a post or page
  • [wp_ad_camp_1]
  • [wp_ad_camp_2]
  • [wp_ad_camp_3]
  • [wp_ad_camp_4]
2. Call one of the functions from your theme’s template file:
  • <?php echo show_ad_camp_1(); ?>
  • <?php echo show_ad_camp_2(); ?>
  • <?php echo show_ad_camp_3(); ?>
  • <?php echo show_ad_camp_4(); ?>

This Plugin in Action

See this plugin in action on Antique HQ.

Download

Download the Plugin from here.

Donation Option

Donation option can be found on my projects page.

Change Log

  • Version 1.1
    • Fixed an issue whereby sometimes Google Adsense code were disappearing from the settings page in some WordPress themes.
  • Version 1.2
    • Devlin from wptheming.com added proper shortcode implementation for placing the ads (this way you don’t have to use the old filtering options anymore)
  • Version 1.3
    • Added shortcode filtering on sidebar
  • Version 1.4
    • Added shortcode filtering on widget text and excerpt

Additional Documentation

How to Add Google Adsense to the Sidebar

You can use the shortcodes (example: [wp_ad_camp_1]) in the sidebar to show Google Adsense ad in the sidebar widget. Simply ad a text widget to your sidebar and place the shortcode in there.
Alternatively, you can add Google Adsense on the sidebar using the ‘Simple Adsense Integration’ Plugin by using the following PHP function:
<?php echo show_ad_camp_1(); ?>
If you are calling the function from the theme’s template file (sidebar.php) then you are fine but there is another way to do this using the widgets which could be more practical in some cases.
1. Download and activate the Executable PHP code plugin if you don’t have it already. This plugin lets you call php functions from the widgets (it’s similar to the Text widget but it lets you execute PHP code too).
2. Go to the widgets menu and add a ‘PHP Code’ widget to the sidebar (where you want to display the Google Adsense block). Now add the following line of code and save the settings:
<?php echo show_ad_camp_1(); ?>
This will display an The Google Adesne ad that is saved in the number one textarea of this plugin.

How to Wrap Text Around a Google Adsense Block

To left align the Adsense block and wrap text around it just use the following div for the Adsense unit in HTML view:
<div style=”float: left;”>
Adsense Goes Here
</div>
To right align the Adsense block and wrap text just change “float: left;” to “float: right;”. So for an example, the following will left align the Adsense Unit that is saved in the Ad Campaign 1 box and wrap text around it.
<div style=”float: left;”>
[wp_ad_camp_1]
</div>
If you need help with this plugin or want to suggest an enhancement/feature then please let me know by leaving a comment in the comment area below.
Also, checkout the list of best WordPress plugins to find out what other plugins you should be using.

No comments:

Post a Comment