wphats

Print Shortcode in WordPress Template

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 1213 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

POSTED ON: Wordpress Basics, Wordpress Support
TAGGED :

One thought on “Print Shortcode in WordPress Template”

Leave a Reply

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