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 2846 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.

One thought on “Print Shortcode in WordPress Template

  • October 17, 2014 at 12:41 am
    Permalink

    Very simple but necessary to know this part for easy solution.

Comments are closed.