WordPress Help – How to Create a Shortcode for Google Adsense Code

by Elaine on October 14, 2011

wordpress killer thesis theme WordPress Help   How to Create a Shortcode for Google Adsense CodeI thought creating shortcodes was a difficult thing to do, but surprisingly it’s not.  I have Wordpress Thesis Theme installed, so this Wordpress tutorial will be geared towards users with the Thesis Theme.  If you do not have Thesis, you can still edit your functions.php file and follow the same steps.

This Wordpress tutorial will guide Thesis theme users how to create a shortcode for Google Adsense code and how to add it into your WordPress posts.

For example, I want:

  • Google Adsense 5 links horizontal to be a shortcode
  • I want to be able to use the shortcode in my posts simply by typing [my5links]
Overview of steps:
  • Login to your Google Adsense to create, configure and get your Adsense code
  • Backup and Edit Thesis custom_functions.php
  • Add shortcode syntax into the Thesis custom_functions.php
  • Create a post and use the Adsense Shortcode
  • View your post
Detailed Steps:
1.  Login to Google Adsense to create,configure and copy Adsense code
  • Create our own Adsense code.
  • Your adsense code will look something like this:
<script type="text/javascript"><!--  google_ad_client = "ca-pub-1719145887610317";  /* 5 Links CMSMIND Shortcode */  google_ad_slot = "7433961634";  google_ad_width = 468;  google_ad_height = 15;  //-->  </script>  <script type="text/javascript"  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">  </script>

2. Backup and Edit Thesis ‘custom_functions.php’

thesis custom functions add adsense shortcode WordPress Help   How to Create a Shortcode for Google Adsense Code

Edit Thesis custom_functions.php

  • Login to your FTP File Manager and take a backup of your Thesis custom_functions.php.
  • The file is located in your thesis themes custom folder, IE:
/wp-content/themes/thesis18/custom/
  • Login to your WordPress Administrator Panel
  • Click on Thesis, Custom File Editor
  • Currently editing, Use the drop down to select ‘custom_functions.php
  • Click on ‘Edit selected file’

3.  Add Shortcode code into Thesis ‘custom_functions.php’

  • In the custom_functions.php file, go to the bottom of the file and append the following code.  Remember to use your own Adsense code:
//create shortcode for adsense 5 links  // Adsense Short code  function Google_Adsense( $atts, $content = null ) {     return '<script type="text/javascript"><!--  google_ad_client = "ca-pub-1719145887610317";  /* 5 links CMSMIND */  google_ad_slot = "9963532559";  google_ad_width = 468;  google_ad_height = 15;  //-->  </script>  <script type="text/javascript"  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">  </script>';  }  add_shortcode('my5links', 'Google_Adsense');
  • Your shortcode string will be [my5links].  Use that anywhere on your WordPress website and Google Adsense 5 links will show up.
  • Click on ‘Save’

4.  Create a post and use the Adsense Shortcode

cmsmind adsense shortcode my5links WordPress Help   How to Create a Shortcode for Google Adsense Code

Add Adsense Shortcode into Post

  • Click on Posts, Add New
  • In the body of the post, add in this text:
[my5links]
  • See the screenshot for an example
  • Save and publish your post.

5.   View your Post

  • View your post and you will see that your shortcode [my5links] will automatically convert to adsense code.
adsense shortcode post preview WordPress Help   How to Create a Shortcode for Google Adsense Code

Adsense Shortcode View Post

Thanks,

Elaine

 WordPress Help   How to Create a Shortcode for Google Adsense Code

Elaine

Elaine is the founder of CmsMind, an online blog providing Joomla and WordPress tutorials. Elaine lives in Toronto and when she is not online, she is either Marathon and Triathlon training or travelling and racing somewhere in the world. Find her also at: Save Money, Premium Themes and Templates, and at Webhosting Tips.

More Posts - Website

Leave a Comment

Captcha Captcha Reload

Older Post:

Newer Post: