Menu
Disclosure: ULTIDA's content is free & reader-supported. We may earn a commission if you click & buy through our links. Your support helps us create the best content & make a difference.
Tutorials

What Is Shortcode In WordPress? (+ How-To)

what is shortcode in wordpress

A WordPress shortcode is a small snippet of code that’s usually indicated by square brackets.

I’m sure you have come across the term shortcode even if you’re a WordPress newbie.

Still, many users reached out to explain to them what’s up with shortcodes.

I’ll explain what tey are, how they work, and how to go about creating your own.

A shortcode adds a specific feature to your posts and pages.

You can PLACE a shortcode ANYWHERE using the text or visual editor.

It will output the contents on your website’s front-end. (Simple!)

LITTLE effort performs GREAT functions.

how do you use a shortcode in your wordpress website

How Do WordPress Shortcodes Work

Even though WordPress is EXTREMELY flexible, you often need to write code to add extra features.

BUT.

If you’re not a developer, writing code is a MISSION IMPOSSIBLE.

That’s where WordPress shortcodes come in.

They are shortened code snippets that look like this: [audio].

They represent a larger piece of code that WordPress executes from a file where it was added.

By default, there are six shortcodes that come with WordPress:

  • Audio — let’s you embed audio files on your website
  • Caption — adds captions to the specified content. Typically used for images but can be used with other HTML elements
  • Embed — allows you to embed other file types and content in WordPress
  • Gallery — adds a basic image gallery to your site
  • Playlist — displays an audio or video playlist
  • vVideo — allows you to embed video files

The default shortcodes are pretty self-explanatory and perform the function that their name suggests.

Beyond that, there are many plugins that use shortcodes. This includes contact forms, image gallery or portfolio plugins, slider plugins, and more.

What is the Use of Shortcode in WordPress

You can use them to add a gallery or a playlist to your post or a page in WordPress. They also work to add content from other websites, such as a Instagram feed.

How Do You Use a Shortcode in Your WordPress Website

You need to copy the shortcode first to add it to any post or page.

Then, log in to your WordPress website and launch the post or page editor.

It’s SIMPLE, paste the shortcode in.

If you’re using the Gutenberg editor, you can use the Shortcode block in the widgets section to add the desired one.

how do wordpress shortcodes work

Keep in mind that some shortcodes ALLOW you to CUSTOMIZE the output.

You can add different parameters to specify exactly what appears as the result of adding a shortcode.

For example, [audio src="audio-file.mp3" loop=”on”] allows you to specify which audio file you want to add to your post or page and set it to loop.

Note: Another thing to remember is that if you’re using shortcodes that came with your theme or a specific plugin, they will STOP WORKING if you change the theme/plugin.

How to Add More Shortcodes to Your WordPress Website

The default shortcodes in WordPress are nice but they’re often not enough.

In some cases, you may want to add a SPECIFIC MESSAGE at the end of your posts or perhaps you want to insert an FAQ section or a button easily.

Luckily, you can add more to WordPress with the help of plugins.

One such plugin is Shortcodes Ultimate.

It has 50+ shortcodes such as accordions, spoilers, drop caps, columns, tabs, and more.

The plugin has 800,000+ active installations and a 5-star rating on the official repository.

We use it, TOO!

how to add more shortcodes to your wordpress website

How to Create Your Own Shortcode In WordPress

Another way is to create your own.

This is useful if you have a specific need or don’t feel like installing an extra plugin with shortcodes you’ll never use.

Here’s how it’s done.

One thing before we proceed: It’s best to create it as a simple plugin that you’ll add to your website if you want to create a custom shortcode.

This will ensure it CONTINUES WORKING even if you update or switch your theme.

For the purposes of this tutorial, we’ll be adding the shortcode function into the functions.php file.

First, we need to write the function that will allow the shortcode to output our simple affiliate disclaimer.

Paste this into the code editor within your functions.php file:

add_shortcode( ‘disclaimer’, ‘affiliate_disclaimer’ );
function disclaimer_init(){
 function affiliate_disclaimer() {
 return “<p><strong>Links with asterisk are affiliate links which means I may earn a small commission if you use them to make a purchase.</strong></p>”;
 }
}
add_action(‘init’, ‘disclaimer_init’);

Save the file.

Next: Go to any of your pages or posts and click Edit to load the editor.

Locate the shortcode widget and then add yours.

You can then preview the page to make sure it works.

Once you’ve verified that the shortcode is there, you can save the page and continue using it.

To learn more about creating shortcodes, you can refer to the official WordPress codex (I used it at the beginning, too):

Final Thoughts

Shortcodes are useful SNIPPETS OF CODE that make it easy for regular users to add a bit of extra functionality to their website without code.

With the tips laid out in this article, you now know what shortcodes are, what they’re used for, and how to create it in WordPress.

All that’s left to do now is to try your hand at creating a simple shortcode for your WordPress website.

It’s easy!

No Comments

    Leave a Reply