Post Pic

How to: Save time by using WordPress shortcodes

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="http://www.wprecipes.com">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:

[wpr]

This short code will output the "Have you checked out WpRecipes today?" message.

2 Responses

Sep 10 2011 10:22

Hi, I had a shortcodes placed in my title of my wp article post for seo results, i.e. {city} using a wp plugin. It is suppose to get indexed in Google, Yahoo, Bing, etc.

I am not sure whether to include “the title with the shortcode {city}”, or just leave the {city} by itself in the article post without the title in order for them to show the {city} i.e. New York without the {}?

I hope this make sense to you?

Aug 20 2012 07:32

Thanks for these short codes! They saved my lot of time :)

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox