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!

Alex Denning

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)!

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

25 Best Free WordPress Themes (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...