How to create a shortcode in WordPress

So this tasks is a basic one. I do need to get a shortcode added into a page. This short code needs to do some functions for a variable given from the URL.

How can i create a shortcode for this? This is easy. For the following code in WordPress editor:

[sealdownload]

We have the following code added into the theme folder on file functions.php :

add_shortcode('sealdownload', 'sealdownloadfunction');

function  sealdownloadfunction() {
    return '<p>Hello World!</p>';
}

To create a shortcode we need to use function add_shortcode. This function have 2 parameters: first parameter is the shortcode used in the text area(in our case sealdownload) and the second is the function that is executed(in our case sealdownloadfunction).

Just use return with the code returned on the function. Do not use echo as this will put the shortcode above the content usually.

Leave a Reply

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