Shortcode Function: An Ease For Bloggers

You 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 short to insert the adsense within my post which I call with simply trigger “[adsense]”. By inserting the code without inverted commas, I was able to insert Google adsense within my post, pre-formatted as per my choice.

How did I do that?

Lets understand the basic code of short code.

function showads() {

return ‘your code here

‘;

}

add_shortcode(‘google_ads’, ‘showads’);

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]”…….

Read complete article on http://www.bloggingjunkie.com/shortcode-function-an-ease-for-bloggers.html

Author :

Comments

If you want a pic to show with your comment, go get a gravatar!