How To Create Shortcodes In WordPress

Hello there, Shortcode is one of the powerful feature of WordPress.In this tutorial we will learn about how easily we can create our custom shortcode in WordPress.

I create a function my_awesome_shortcode() and output Hello World by it. Now I want to create a shortcode [awesome]. And when I add this shortcode to any WordPress page or post, then it will return the value of my_awesome_shortcode() function. Simple Yeah ?

Well, take a look on the code.


function my_awesome_shortcode(){ 
echo "Hello World"; 
}
add_shortcode('awesome','my_awesome_shortcode');

Add this code to functions.php then add this shortcode [awesome] to any of your page or post.

add_shortcode() is an action hook that used to create shortcode. First parameter is the shortcode name that we use between a square brackets [awesome] . Second parameter is the function name that will return a value when we use this shortcode.

 

 

Leave a Reply

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