how to use shortcodes in wordpress posts

Short code api is introduced in wordpress from 2.5 version. Since short code is very popular and used by wordpress plugin developers. Many wordpress theme and plugin developers do use the shortcode api regularly.

how to use shortcodes in wordpress posts

how to use shortcodes in wordpress posts

how to use shortcodes in wordpress posts

Using shortcode api is very easy. If you want to use the shortcode in your wordpress theme then open your functions.php file and put following code. Here is example for using shortcode.


function wordpressapi_content() {

echo "Hello World";

}

add_shortcode('wordpressapi_content', 'wordpressapi_content');

Create any page and just put following line in that post or page.

[wordpressapi_content]

If you put following code in your page or post then you can see the hello world content in your page or post.

If you want to add the google adsence using shortoce then use the following code.


function google_adsence($atts) {
 return ' "<script type="quot;text/javascript"quot;">"<!--
google_ad_client = "quot;ca-pub-4949877136251097"quot;;
/* 160x600, created 4/7/08 */
google_ad_slot = "quot;5503695728"quot;;
google_ad_width = 160;
google_ad_height = 600;
//--">
"</script">
"<script type="quot;text/javascript"quot;
src="quot;http://pagead2.googlesyndication.com/pagead/show_ads.js"quot;">
"</script">
'
}

add_shortcode('google_adsence', 'google_adsence');

Then just put the following words in your post or page or widget section.

[google_adsence]

Your adsence will be displayed. For advanced information about shortcode you should check following URL

http://svn.automattic.com/wordpress-tests/wp-testcase/test_shortcode.php

If you are having any issues or question about shortcode then please write to me.

Add a Comment

Your email address will not be published. Required fields are marked *