Print Shortcode in WordPress Template

Shortcode API introduced in wordpress since 2.5 and it refers to a simple set of functions for creating macro codes for use in post content. Shortcode can be used to both with core code(theme) and plugins. For example, the following shortcode (in the post/page content) would add a image gallery into the page:

[image_gallery]

 

Sometimes shortcode have dynamic value where user have option to insert values in that particular option. Below example shows if need value how many slider image will show and  what will be the slider width & height:

[image_gallery slides=”5″ width= “900px” height=”400px”]

Besides, shorcode may have opening and closing shortcode. Below example shows having the same option value if the slider image have Title in top then it needs to a closing shortcode.

[image_gallery slides=”5″ width= “900px” height=”400px”]Image Slider Top TItle [/image_gallery]

All the above examples can be used to insert their in rich area(editor) to invoke the content in post/page. But, if you like to use your shortcode in template where you have your own access to focus in fixed area, you can use the below code to print:

echo do_shortcode('[image_gallery]');

Moreover, if you have there is opening and closing shortcode then use the following code:

echo do_shortcode('[image_gallery]'.$your_text.'[/image_gallery]');

Remember, If there are no shortcode tags defined, then the content will be returned without any filtering. This might cause issues if a plugin is disabled as its shortcode will still show up in the post or content.

This post has already been read 2850 times!

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

More Posts

Mehedi Hasan

Cool WordPress Developer having much agile experience to develop any kind of WordPress sites & plugins. Also good in troubleshooting, fixing & making any kind of tweaks for WP site.

Recent Posts

WP Share A Friend – A Way to Capture Lead

What is Lead Capture: In general sense lead capture designates a process or way of…

5 years ago

Unlimited Modal POPUPS on MouseClick

Introduction Unlimited Modal POPUPS on MouseClick: Everyone knows about popup during site visits and most…

5 years ago

WordPress Pregnancy Calculator Plugin

Brief about Pregnancy Calculator : This WordPress Pregnancy Calculator plugin allows users to display an…

5 years ago

Interactive Service Plugin with Hover Effects VC

Introduction About this Service Plugin: This Visual Composer Service Plugin works as an addon to…

6 years ago

WP Dynamic Query String

Introduction of Dynamic Query String : This plugin allows user to set dynamic query string…

6 years ago

How to make scroll PDF in iFrame for iPAD Safari

There is an occasional bug for iPhone and iPad even they are designed as well and…

7 years ago