How to create shortcode in wordpress

Create shortcode

1) Open  function.php

2) Create a function and do something with the function.


function myfunction(){
echo 'Hi! My Name is Dharminder Singh';
add_shortcode (' myfunction_shortcode','myfunction');

3) Here ‘add_shortcode’ function (WP function) is used for create short code of your function, First parameter is used for short code and second is your function name.

Now add short code in editor like: [myfunction_shortcode]. If you want to add short code in a file like template then use do_shortcode WP function.


echo do_shortcode('[myfunction_shortcode]')'; ?>

2 thoughts on “How to create shortcode in wordpress

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s