How to create shortcode for AdSense banners in wordpress

In this brief wordpress tutorial I`m going to cover creating a shortcode for banner insertion in your posts. This is a great solution, especially if you don`t want banners shown on all of your posts, or you want to place the banners in accordance to the articles/text of your blog post. If you`re not familiar with the wordpress shortcode api you can visit the wordpress codex, the guys there got it covered perfectly. The code below is designed for Google Adsense, but can easily be adjusted for any type of affiliate programs.

In order to use the code paste it at the bottom of your theme`s functions.php file right before the closing php tag.

function adsense_func( $atts ){
 $ad = '

//You can change the code between the <script> tags with your personal Ad code
 <script type="text/javascript"><!--
 google_ad_client = "Adsense ID";
 google_ad_width = 336;
 google_ad_height = 280;
 google_ad_format = "336x280_as";
 google_ad_type = "text";
 google_ad_channel = "";
 google_color_border = "ffffff";
 google_color_bg = "FFFFFF";
 google_color_link = "0000FF";
 google_color_text = "000000";
 google_color_url = "11593C";
 <script type="text/javascript" src=""></script>

//Finish editing

 return $ad;
add_shortcode( 'adsense', 'adsense_func' );

After you save your functions.php file, you`re ready to test your shortcode. Open some post, or add a new one and paste [adsense] somewhere in the post. After you save it, you`ll see your banner showing in the exact same place, where you placed your shortcode.