How to: Save time by using WordPress shortcodes

December 12, 2008 at 8:56 am

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 wprecipes() {
    return 'Have you checked out <a href="">WpRecipes</a> today?';

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('wpr', 'wprecipes');

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 “Have you checked out WpRecipes today?” message.