Post image for Shortcode Function: An Ease for Bloggers

Shortcode Function: An Ease for Bloggers

by Bobby Jay

short codeYou probably have faced the situation where you want to insert some special function of your own choice in your article. If you are unable to find a plugin fulfilling your requirement, you need to write your own snippet. But this is not easy. We are bloggers, not the coders.

Writing a plugin in php is not an easy task and one have to get familiar with basics at least. So how to get our custom made feature in WordPress.

I faced this situation while inserting Google adsense in middle of my posts. I was supposed to rely on plugin and to manually insert the code in my posts. Matter is not ended here. I also need to customize the output of plugin. All of this became very hectic. Then after Googling on net, I found a solution and am very happy with it.

 WordPress supports shortcode. What is short code?

Short code enables you to make you custom made function or event, triggered by easy to remember text line. For example, I created a shortcode to insert the adsense within my post which I call with help of simple syntax “adsense” , word adsense is with in braces. By inserting the code , I am able to insert Google adsense within my post, pre-formatted as per my choice.

[adsense]How did I do that?Lets understand the basic code of short code. 

function showads() {
return 'your code here
';
}
add_shortcode('adsense', 'showads');

We have following benefits of using shortcode functionality;

  • Time saving activity,
  • Custom Made Event,
  • Ability to design Custom Functionality,
  • Prevents from coping and pasting long codes,
  • No need to install plugin,
  • Database is not modified and have compact size.  

We declared a function called showads, and instructed WordPress to add it as short code which is called with the help of text line “adsense”. So my shortcode command to insert the adsense is “[google_ads]”.
You can create your own function by simply putting the code with in the code given above. Eight different uses of shortcode have been demonstrated in an article. Visit it , understand the code and have fun.

Link: 8 fun & useful shortcode functions for wordpress

Related posts:
  1. Show Adsense Only to Search Engine Visitors
  2. 12 Essential Plugins for WordPress
  3. Thesis Customisation to Show Thumbnail in Teaser
  4. BloggingJunkie Redesigned using Thesis Framework

Previous post:

Next post: