How to Create Your Own WordPress ShortCodes


Shortcodes were introduced in WordPress version 2.5. It also comes bundled with many plugins and themes. Shortcodes are something inside square brackets which is replaced with content in post and page. In WordPress based websites, you are not allowed to add PHP codes in posts and pages. But you can create custom functions and then shortcodes of those functions to run within the function. If you are new to WordPress and do not know how to create shortcodes for your function, you are at right place. In this post, we will see how to create shortcodes for a custom function.

WordPres Shortode

Before creating shortcode, you need to create a call back function. This function will be called each time the shortcode will encounter in post or page.. Open functions.php file of your theme and add the sample code. mycustomFunction is the call back function for shortcode Myfn.

Whenever you want to add the mycustomFunction within post or page, just add [Myfn] shortcode.

Sometimes, there is the need of passing values in the function. So, we have to create shortcodes that can pass value. See the example given below:

You can use this shortcode by passing values of height and width.

Try it by yourself and comment below if you are facing any problem.



Written by Deepanker

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Leave a Reply

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


Download Entire Wikipedia With XOWA App

Free Skype Call Recording Software

Top 5 Free Skype Call Recording Software