Create simple 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 wp123() {
    return 'Have you checked out <a href="http://www.wp123.info">wp123</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('wp123', 'wp123');
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:
[wp123]
This short code will output the "Have you checked out wp123 today?" message.

Leave a Reply