Save time by using WordPress shortcodes

December 13, 2008 · Print This Article

Shortcodes have been introduced in WordPress 2.5. They’re hooks which allow you to call a php function simply by typing something like [shortcode].

It is a great way to save time on repetitive tasks. Just read on to find out how to use them.

To create a shortcode, you first have to create a php function.

Let’s start with a basic one. Append it to your functions.php file.

function caption_shortcode($atts, $content = null) {
return 'Welcome~~';
}

Once you created your function, you have to use the add_shortcode() function. paste this code just after your function on the functions.php file from your theme:

add_shortcode('caption', 'caption_shortcode);

You’re now able to use the wpr shortcode. To do so, paste the following line of code on the editor (in HTML mode) while writing a post:

This short code will output the “welcome~~” message.

Related article: http://codex.wordpress.org/Shortcode_API


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.