Wordpress Enable Adsense Shortcode

By gilbitron in PHP on 29/04/2009 at 08:37

Views: 1665
Tagged: wordpress, shortcodes, php, adsense
URL: http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/

Starter:

Wordpress allows developers and theme creators to write functions that allow the user to use shortcode, i.e., [adsense]. This kind of "pseudo" code makes it easy for end users to insert elements where they would like without knowing about coding.

Knowing that we can create shortcodes, we can create one to insert a Google Adsense ad anywhere in our theme.

Main Course:

function showads() {  
     	return '<div id="adsense"><script type="text/javascript"><!--  
     	google_ad_client = "pub-XXXXXXXXXXXXXX";  
    	 google_ad_slot = "4668915978";  
    	 google_ad_width = 468;  
    	 google_ad_height = 60;  
    	 //-->  
		 </script>  
 
		 <script type="text/javascript"  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">  
 		 </script></div>';  
 }  
 
 add_shortcode('adsense', 'showads');

Expand Report Code | Install Coda Clip

Please log in to vote.

Compliments to the Chef

No comments yet...

How was your Meal?


  • Allowed HTML: <b><strong><u><i><em><a>

  • Why ask? It helps us stop spam comments.