ten80snowboarder

Simple WordPress Google Ads Shortcode

Jul 10th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. /* ADD THIS TO YOUR functions.php FILE ----------------------------------------------------------------------------- */
  2. function ten80_google_adsense( $attr, $content ) {
  3. //  Variables for use in script -----------------------------------------------------------------------------------
  4.     $pub_account    = 'pub-[your-account-number-here]';
  5.     $size   = ( !isset( $attr['size'] ) ? $size = '300x250' : $size = $attr['size'] );
  6.     $sizeA  = explode('x', $size);
  7.     $sizeW  = $sizeA[0];
  8.     $sizeH  = $sizeA[1];
  9.  
  10. //  Output the Google Ads block -----------------------------------------------------------------------------------
  11.     echo '
  12.         <script type="text/javascript">
  13.             google_ad_client    = "'.$pub_account.'";
  14.             google_ad_width     = '.$sizeW.';
  15.             google_ad_height    = '.$sizeH.';
  16.             google_ad_format    = "'.$size.'_as";
  17.             google_ad_type      = "text_image";
  18.             google_color_border = "FFFFFF";
  19.             google_color_bg     = "0000FF";
  20.             google_color_link   = "FFFFFF";
  21.             google_color_text   = "000000";
  22.             google_color_url    = "008000";
  23.         </script>
  24.         <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  25.     ';
  26. }
  27. add_shortcode('googleads', 'ten80_google_adsense');
  28.  
  29. /* CALL THE SHORTCODE LIKE THIS ------------------------------------------------------------------------------------ */
  30. /*
  31. Specify a banner size:  [googleads size="460x60"]
  32. Defaults to 300x250:    [googleads]
  33. */
Add Comment
Please, Sign In to add comment