Learn WordPress
Home » Script

Adsense Injection Plugin in Single Post

There are a lot of ways when you need to increase your Google Adsense earning. One of them is to inject into your content.

adsense injection

You can do this by manually by entering a code of your Google Adsense tucked inside the content, but this will be very troublesome when you need to change your design of your website theme because you will extra trouble to edit one by one the code that you enter previously to customize the colors, banners and etc.

By using Adsense Injection plugin, then you don’t need to re-edit already post one by one.
Here the simple plugin code:

<?php

/*

Plugin Name: Adsense

Version: 0.1

Plugin URI: http://www.aming.info

Description: Inserts Google Adsense inside your posts where you see fit. Simple to use: Edit the adsense.php file to use your Adsense code instead of mine; Activate the plug-in; Click the “Adsense” button on the quicktags bar to insert the Adsense marker in your posts. Please make sure you read <a href=”https://www.google.com/adsense/policies”>Google’s TOS</a> before using this plugin!

Author: Web Ware Craft Technologies

Author URI: http://www.aming.info

*/

/*

adsense

This function replaces <!–adsense–> tags with actual Google Adsense code

*/

function phord_insert_adsense($data) {

$tag = “<!–adsense–>”;

/**************************************************************************

** Replace this HTML code with your own customized Google Adsense code. **

**************************************************************************/

$adsense_code = ‘

<!– Begin Google Adsense code –>

<script type=”text/javascript”><!–

google_ad_client = “pub-7093331452******”;

/* 336×280,created6/7/10 */

google_ad_slot = “6128139020”;

google_ad_width = 336;

google_ad_height = 280;

google_language = “en”;

//–>

</script>

<script type=”text/javascript”

src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>

</script>

<!– End Google Adsense code –>

‘;

/************************************************** ************************

** All done! No more changes need to be made below this line! Enjoy! **

************************************************** ************************/

return str_replace( $tag, $adsense_code, $data );

}

add_filter(‘the_content’, ‘phord_insert_adsense’);

//—- The following AddAButton code comes from the Edit Button Template

//—- found here: http://codex.wordpress.org/Plugins

//—- and originally written by Amming W. Widhonno

//—- It was originally here: http://www.aming.info/category/script/

//—- But I had trouble downloading it from there.

add_filter(‘admin_footer’, ‘phord_InsertAdsenseButton’);

function phord_InsertAdsenseButton()

{

if(strpos($_SERVER[‘REQUEST_URI’], ‘post.php’))

{

?>

<script language=”JavaScript” type=”text/javascript”><!–

var toolbar = document.getElementById(“ed_toolbar”);

<?php

edit_insert_button(“Adsense”, “adsense_button”, “Adsense”);

?>

function adsense_button()

{

edInsertContent(edCanvas, ‘<!-‘+’-adsense-‘+’->’);

}

//–></script>

<?php

}

}

if(!function_exists(‘edit_insert_button’))

{

//edit_insert_button: Inserts a button into the editor

function edit_insert_button($caption, $js_onclick, $title = ”)

{

?>

if(toolbar)

{

var theButton = document.createElement(‘input’);

theButton.type = ‘button';

theButton.value = ‘<?php echo $caption; ?>';

theButton.onclick = <?php echo $js_onclick; ?>;

theButton.className = ‘ed_button';

theButton.title = “<?php echo $title; ?>”;

theButton.id = “<?php echo “ed_{$caption}”; ?>”;

toolbar.appendChild(theButton);

}

<?php

}

}

?>

You just need to edit the Google Adsense code and save it as adsense.php and then upload into your /wp-content/plugins directory and active it at wp-admin/plugins.php.

When you create new post you just need to click “Adsense” button at quicktags bar to inject Adsense into your content posts.

adsense injection

adsense injection

FREE Cloud Storage