Skip to content

Write Faster With WordPress’ Shortcodes

WordPress has many somewhat hidden features and one of my favourites are shortcodes. In this post we’ll learn exactly what they are, when to use them, why they’re so brilliant and how to use them.

Shortcodes. What are they?

In a nutshell, shortcodes are shortcuts of writing phrases or words. Here’s an example. On [wp] whenever I write [wp] it always links to the homepage. That’s because I’ve set up a shortcode so all I have to do is type [wp] and WordPress outputs <a href="https://wpshout.com">WPShout</a>.

Another example – if I type [themes] WordPress outputs <a href="https://wpshout.com/category/themes/">WordPress Themes</a>. This allows me to quickly cross promote other sections of the site and link to other pages with minimal effort on my part. I do use them quite a lot – why not [f] or [s]? All I’m typing is [f] and [s ].

So how do I use them?

Now that you’re convinced shortcodes are the best thing since sliced bread, you’ll obviously want to know how to use these shortcodes. It’s really easy. First, you’ll need the functions.php file open. We’ll come back to that in a sec – first lets look at the [wp] example I showed earlier. In my functions.php file I’ve got the following:

function wpshout() {
    return '<a href="https://wpshout.com">WPShout</a>';
}
add_shortcode('wp', 'wpshout');

Which as we’ve seen outputs a link to WPShout.com. The important thing to learn from the example is the formatting: start off with a function, then return what we want to be displayed and then add the shortcode. The first needs to be what you want to shorten to and the second the same as the function. Another example – I want WordPress to output ‘cheese’ when I type [c]. Using the same formatting as the last example, you’d have:

function cheese() {
    return 'cheese';
}
add_shortcode('c', 'cheese');

So when should I use them?

All the time actually. They save an awful lot of time for useful little things. Enjoy!

Yay! 🎉 You made it to the end of the article!
Alex Denning
Share:

3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ahorrar tiempo en WordPress con atajos | Marcial Soto
January 9, 2010 6:59 am

[…] al ingresar en el post el shortcode marcialsoto.com. Fácil, ¿no?1 Este truco lo he aprendido de WPShout […]

wordpress shortcodes kick ass (or: shortcodes, an affiliate marketer’s best friend) | jazzsequence
December 14, 2009 7:11 pm

[…] always posts awesome tips, tricks, and hacks for WordPress.  you can take a look at his post Write Faster with WordPress Shortcodes for another explanation of how they […]

jazzsequence » » wordpress shortcodes kick ass (or: shortcodes, an affiliate marketer’s best friend)
December 14, 2009 4:55 pm

[…] always posts awesome tips, tricks, and hacks for WordPress.  you can take a look at his post Write Faster with WordPress Shortcodes for another explanation of how they […]

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!